【发布时间】:2019-04-10 18:30:39
【问题描述】:
我在我的应用程序中添加了一个深层链接,它将活动映射到我网站上的特定网页(链接参考:https://developer.android.com/training/app-links/deep-linking)。
在我的 Java 代码中处理深层链接时,getAction() 和 getData() 方法给了我 null 值。
我在这里尝试对其进行测试:https://firebase.google.com/docs/app-indexing/android/test(这给了我完美的结果)但是单击时,相同的链接会在网络浏览器中而不是在我的应用程序中打开。
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
我希望如果应用程序存在,那么在单击链接时应该打开它,否则链接将打开网页。 我在哪里错过了什么?
【问题讨论】:
-
在我的 Android 应用中实现深层链接时,我也面临同样的问题。
-
我在我的安卓应用程序中使用谷歌提供的深层链接。我已将我的 android 应用程序的活动映射到我网站的网页。我想知道,如果我们单击该特定页面的链接,它应该将其重定向到我的应用程序并在应用程序存在时打开该特定活动或者在浏览器中打开网页。如果可能,请协助我解决问题。谢谢!
-
@AnirudhMishra,你找到解决方案了吗?
-
您是否尝试过关闭/杀死您的应用程序然后运行测试?因为可能的问题是您从应用程序开始就已经有了意图。在这种情况下,您必须使用 override onNewIntent 函数检查新意图。
-
@TomasIvan,谢谢 - 你完全正确。为您的答案添加了加号:)
标签: java android firebase indexing deep-linking