【问题标题】:Android Deep linking omit certain urlAndroid 深度链接省略某些 url
【发布时间】:2017-05-16 07:02:43
【问题描述】:

我已成功实现到我的应用的深层链接,但我遇到了一个问题。

<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>

此意图过滤器处理所有链接,但我不想捕获某个 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 android-manifest deep-linking


    【解决方案1】:

    如果我正确理解您的问题,您希望从某个 URL 列表中排除特定 URL。您尝试的是这样做的好方法。

    android:pathPattern 不理解你所说的复杂的正则表达式模式。

    我认为解决您的问题的唯一方法是更改​​您想要省略的 URL。更改主机或该 URL 的一部分,或将名称 example.com 更改为,例如,example2.com/hello/redirect/

    【讨论】:

    • 我明白你的意思。这对我来说是最后的手段。但在此之前,我只需要知道是否有任何我可以实施的解决方案来解决这个问题。
    【解决方案2】:

    Android deep linking mechanism 不提供明确排除某些 URL 的方法:您可以在 either 中包含带有 android:path 的明确路径,包含与前缀匹配的路径 android:pathPrefix 或匹配通配符与 android:pathPattern可以使用*.*

    在您的情况下,您必须使用"/" 并使用您的应用(包括您的主页)打开指向您网站的每个链接,或者让每个深层链接共享一个公共前缀。

    你也可以看看airbnb的DeepLinkDispatch库,好像是allow excluding specific URLs

    【讨论】:

    • 我的主页不加“/”怎么办
    • 似乎 airbnb 的 DeepLinkDispatch 库会列出(同时点击深层链接)我们的目标应用以排除 URL。
    猜你喜欢
    • 2015-07-23
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    相关资源
    最近更新 更多