Android 深度链接路径、pathPrefix 或 pathPattern 不起作用

Bas*_*ijk 5 android deep-linking ionic-framework capacitor

我试图让 Android 深度链接仅适用于特定的网址,例如:

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

当我将数据部分更改为:

<data android:scheme="https" android:host="books.com" android:path="/book/nice-book-1" />
Run Code Online (Sandbox Code Playgroud)

或者

<data android:scheme="https" android:host="books.com" android:pathPrefix="/book" />
Run Code Online (Sandbox Code Playgroud)

或者

<data android:scheme="https" android:host="books.com" android:pathPattern="/book/..*" />
Run Code Online (Sandbox Code Playgroud)

仅匹配/book后跟一个 slug,它不起作用。

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

当仅将几个 url 与 slugs 匹配时,是否有人遇到过相同的问题?

Bas*_*ijk 4

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

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

<data android:scheme="https" android:host="books.com" />
Run Code Online (Sandbox Code Playgroud)

是唯一可行的道路。

使用时:

<data android:scheme="https" android:host="books.com" android:path="/book/nice-book-1" />
Run Code Online (Sandbox Code Playgroud)

或者

<data android:scheme="https" android:host="books.com" android:pathPrefix="/book" />
Run Code Online (Sandbox Code Playgroud)

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