首页 > 解决方案 > Android 深层链接路径、pathPrefix 或 pathPattern 不起作用

问题描述

我正在尝试使 Android 深度链接仅适用于特定的 url,例如:

所以http://books.com/about一直链接到网页

我的作品中的此配置AndroidManifest.xml并在我的应用程序中打开正确的页面。问题是这与books.com上的每一页都匹配

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="@string/custom_url_scheme" />

    <data android:scheme="https" android:host="books.com" />
</intent-filter>

当我将数据部分更改为:

<data android:scheme="https" android:host="books.com" android:path="/book/nice-book-1" />

或者

<data android:scheme="https" android:host="books.com" android:pathPrefix="/book" />

或者

<data android:scheme="https" android:host="books.com" android:pathPattern="/book/..*" />

只匹配/book一个蛞蝓,它不起作用。

我已经在 Stackoverflow 上找到了许多类似的问题,但它们要么已经过时,要么无法处理 url 与 slug 一起使用的情况。

在仅将几个 url 与 slug 匹配时,是否有人遇到过同样的问题?

标签: androidionic-frameworkdeep-linkingcapacitor

解决方案


我花了很长时间才弄清楚这一点。所以我会回答我自己的问题以节省其他人宝贵的时间。

事实证明,当通过 Android Studio 在设备上运行 Android 应用程序时

<data android:scheme="https" android:host="books.com" />

是唯一可行的途径。

使用时:

<data android:scheme="https" android:host="books.com" android:path="/book/nice-book-1" />

或者

<data android:scheme="https" android:host="books.com" android:pathPrefix="/book" />

这些仅在您的设备上使用签名版本的应用程序时才有效。这可能是因为您assetlinks.json有一个sha256_cert_fingerprints只有在使用签名的应用程序时才能验证的内容。


推荐阅读