【问题标题】:Android custom scheme deep link does not work on clickAndroid自定义方案深层链接在点击时不起作用
【发布时间】: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


【解决方案1】:

* 不是 android:host 的有效值。 只需将其删除即可。

此外,此方法在很大程度上依赖于首先处理 url 的应用程序。 如果您的浏览器不让系统处理非 http 方案,您将无法使其工作。

【讨论】:

  • 感谢您的回答。我删除 * 没有任何效果。可能是你最后说的,我的浏览器不让系统处理非http方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-18
  • 1970-01-01
  • 2014-10-01
  • 2020-09-21
  • 1970-01-01
相关资源
最近更新 更多