2017-01-02 83 views
3

我已经成功实现了与我的应用的深层链接,但是我遇到了问题。Android深层链接省略了特定的网址

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

我试了一下,到目前为止:

我试图进入所有的我想要手动捕捉的网址

<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/"> 
... 

但t当我的主页URL https://www.example.com不起作用。

如果我使用

android:pathPrefix="/" 

,那么这将再次开始捕获所有的网址,包括我想省略的URL。

我也尝试过使用android:pathPattern,但它不能理解像这样的复杂正则表达式^((?!redirect).)*$,当我在字符串和全部字符串中尝试它时,它工作正常。

任何人都知道如何省略某些网址?

UPDATE:

正如@PLNech here建议,我说,我需要使用android:pathPrefix赶上并使用android:path: "/"的所有URL赶上我的主页即的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/"> 

回答

5

Android deep linking mechanism不提供一种方式来明确排除在Android深度链接机制的一些网址:您可以either包括与android:path明确的路径,包括匹配与android:pathPrefix前缀或android:pathPattern匹配通配符,你可以使用*或路径.*

在你的情况,你必须要么使用"/",并有链接到你的网站,你的应用程序(包括您的主页)打开,或有充分的深层链接都有一个共同的前缀。

你也可以看看airbnb的DeepLinkDispatch库,这似乎是allow excluding specific URLs

2

如果我正确理解您的问题,您希望从特定的URL列表中排除特定的URL。你所尝试的是一个很好的方法来做到这一点。

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

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

+1

我明白你的观点。这对我来说是最后的选择。但在此之前,我只需要知道我可以采取哪些解决方案来解决问题。 –