我已成功实现到我的应用程序的深度链接,但我遇到了一个问题。
<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:host="*.example.com"
android:scheme="https"/>
</intent-filter>
这个 intent 过滤器处理所有链接,但我不想捕获某个 url,即
https://www.example.com/hello/redirect/
到目前为止我尝试了什么:
我尝试输入所有我想手动捕获的 URL
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/m/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/c/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/p/">
...
但是我的主页 URL https://www.example.com
不起作用。
如果我用
android:pathPrefix="/"
然后这将再次开始捕获所有 URL,包括我想省略的 URL。
我也尝试过使用 android:pathPattern
,但它无法理解像这样的复杂正则表达式 ^((?!redirect).)*$
效果很好当我在字符串中尝试它时。
有人知道我怎样才能省略某些网址吗?
更新:
根据@PLNech 的建议here ,我添加了所有需要使用 android:pathPrefix
捕获的 URL,并使用 android:path: "/"
捕获我主页的 URL,即 https://www.example.com/
<data
android:host="*.example.com"
android:scheme="https"
android:path="/"/>
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/m/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/c/">
<data
android:host="*example.com"
android:scheme="https"
android:pathPrefix="/p/">
最佳答案
Android deep linking mechanism不提供明确排除某些 URL 的方法:您可以 either使用 android:path
明确包含路径,包括使用 android:pathPrefix
匹配前缀的路径或使用 android:pathPattern
匹配通配符的路径,您可以在其中使用*
或 .*
.
在您的情况下,您将不得不使用 "/"
并使用您的应用打开指向您网站的每个链接(包括您的主页),或者让每个深层链接共享一个公共(public)前缀。
你也可以看看airbnb的DeepLinkDispatch图书馆,似乎allow excluding specific URLs .
关于Android 深度链接省略某些 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41422305/