小编Ani*_*hra的帖子

从深层链接的意图中获取空值

我在我的应用程序中添加了一个深层链接,该链接将活动映射到我网站上的特定网页(链接称为:https : //developer.android.com/training/app-links/deep-linking)。虽然在处理我的Java代码中的深层链接,getAction()getData()方法给我空值。我尝试在此处进行测试:https : //firebase.google.com/docs/app-indexing/android/test(这给了我完美的结果),但是单击该链接时,它会在Web浏览器中而不是在我的应用程序中打开。

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>
Run Code Online (Sandbox Code Playgroud)

Java代码:

    Intent intent = getIntent();
    String action = intent.getAction(); // getting null value here
    Uri data = intent.getData(); // getting null value here
Run Code Online (Sandbox Code Playgroud)

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

java indexing android deep-linking firebase

5
推荐指数
2
解决办法
556
查看次数

标签 统计

android ×1

deep-linking ×1

firebase ×1

indexing ×1

java ×1