【发布时间】:2021-02-05 10:48:30
【问题描述】:
我搜索了很多,我阅读了很多答案,但不幸的是我没能成功。
我正在我的应用程序上测试深层链接,我无法让自定义方案 url 在点击时工作。
我的清单代码是:
<activity android:name=".ui.activities.home.HomeActivity"
android:exported="true"
android:launchMode="singleTask">
<!-- for http links -->
<intent-filter android:label="testHttpDeepLink">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "http://www.myapp.com/test” -->
<data android:scheme="http"
android:host="www.myapp.com"
android:pathPrefix="/test" />
</intent-filter>
<!-- for app links -->
<intent-filter
android:label="testAppDeepLink">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Accepts URIs that begin with "myapp" -->
<data android:scheme="myapp"
android:host="*"/>
</activity>
当我尝试在工作室终端上对其进行测试时,第二种格式可以正常工作。所以如果我写
adb shell am start -a android.intent.action.VIEW -d "myapp://test"
应用主页活动打开正确。但是当我尝试从链接打开它时它不起作用。例如,我用可能的格式向自己发送一封电子邮件,例如
1 -> www.myapp.com/test
2 -> myapp://test
第一个工作正常,但第二个不行。它显示消息错误:net::ERR_UNKNOWN_URL_SCHEME 当我单击 URL 时。只有当我长按并选择打开时,我才会进入应用主页活动。
【问题讨论】:
-
(我删除了scheme标签,因为它显然与Scheme编程语言无关)
标签: android deep-linking