Android 深层链接省略某些 url
Android Deep linking omit certain url
我已经成功地实现了到我的应用程序的深度链接,但我遇到了一个问题。
<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/
到目前为止我尝试了什么:
我尝试输入所有我想手动捕获的 URLs
<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).)*$
当我在字符串和所有字符串中尝试它时它工作正常。
有人知道我怎样才能省略某些 URL 吗?
更新:
根据@PLNech 的建议, I added all the URLs that I need to catch using android:pathPrefix
and use android:path: "/"
to catch the URL of my home page i.e. 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/">
如果我对你的问题的理解正确,你想从特定的 URL 列表中排除特定的 URL。你试过的是一个很好的方法。
android:pathPattern
不明白你说的复杂的正则表达式模式。
我认为解决您的问题的唯一方法是更改您要省略的 URL。更改主机或其中的一部分 URL,或将名称 example.com
更改为 example2.com/hello/redirect/
。
Android deep linking mechanism does not provide a way to explicitly exclude some URLs: you can either 包含带有 android:path
的显式路径,包含与带有 android:pathPrefix
的前缀匹配或与 android:pathPattern
匹配的通配符的路径,您可以在其中使用 *
或 .*
.
在您的情况下,您将不得不使用 "/"
并让 每个 link 使用您的应用打开您的网站(包括您的主页) ,或者让每个深度 link 共享一个公共前缀。
你也可以看看airbnb的DeepLinkDispatch library, which seems to allow excluding specific URLs。
我已经成功地实现了到我的应用程序的深度链接,但我遇到了一个问题。
<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/
到目前为止我尝试了什么:
我尝试输入所有我想手动捕获的 URLs
<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).)*$
当我在字符串和所有字符串中尝试它时它工作正常。
有人知道我怎样才能省略某些 URL 吗?
更新:
根据@PLNech 的建议android:pathPrefix
and use android:path: "/"
to catch the URL of my home page i.e. 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/">
如果我对你的问题的理解正确,你想从特定的 URL 列表中排除特定的 URL。你试过的是一个很好的方法。
android:pathPattern
不明白你说的复杂的正则表达式模式。
我认为解决您的问题的唯一方法是更改您要省略的 URL。更改主机或其中的一部分 URL,或将名称 example.com
更改为 example2.com/hello/redirect/
。
Android deep linking mechanism does not provide a way to explicitly exclude some URLs: you can either 包含带有 android:path
的显式路径,包含与带有 android:pathPrefix
的前缀匹配或与 android:pathPattern
匹配的通配符的路径,您可以在其中使用 *
或 .*
.
在您的情况下,您将不得不使用 "/"
并让 每个 link 使用您的应用打开您的网站(包括您的主页) ,或者让每个深度 link 共享一个公共前缀。
你也可以看看airbnb的DeepLinkDispatch library, which seems to allow excluding specific URLs。