在深层链接中从intent获取null值

问题描述 投票:3回答:2

我添加了一个指向我的应用程序的深层链接,该链接将活动映射到我网站上的特定网页(链接引用:https://developer.android.com/training/app-links/deep-linking)。在处理我的Java代码中的深层链接时,getAction()getData()方法给出了null值。我在这里尝试测试:https://firebase.google.com/docs/app-indexing/android/test(这给了我完美的结果)但是同样的链接在A网页浏览器中打开而不是在我的应用程序中点击时打开。

Android清单代码:

<activity
    android:name=".MainActivity"
    android:screenOrientation="portrait"
    android:launchMode="singleTask"
    android:exported="true">

    <tools:validation testUrl="https://www.mywebsite.com/xyz" />
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:scheme="https"
            android:host="www.mywebsite.com"
            android:pathPrefix="/xyz" />
    </intent-filter>
</activity>

Java代码:

    Intent intent = getIntent();
    String action = intent.getAction(); // getting null value here
    Uri data = intent.getData(); // getting null value here

我希望如果应用程序存在,那么应该在单击链接时打开它,否则链接将打开网页。我错过了哪里和什么?

java android firebase indexing deep-linking
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.