我已经成功地实现了与我的应用程序的深度链接,但是我遇到了一个问题。
<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/">
...但是我的主页网址https://www.example.com不起作用。
如果我用
android:pathPrefix="/"然后,这将开始再次捕获所有的url,包括我想省略的url。
我也尝试过使用android:pathPattern,但是它无法理解像这个^((?!redirect).)*$这样复杂的正则表达式--当我尝试使用字符串和所有的时候,这个正则表达式工作得很好。
有人知道我怎么能省略某些URL吗?
更新:
正如@PLNech 这里所建议的那样,我使用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/">发布于 2017-01-02 13:48:09
Android深联机制没有提供一种显式排除某些URL的方法:您可以在任一中使用android:path显式包含路径,可以包含与android:pathPrefix匹配前缀的路径,或者可以在使用*或.*的情况下将通配符与android:pathPattern匹配。
在您的情况下,您将不得不使用"/",让与您的应用程序(包括您的主页)打开到您的网站的每个链接,或者让每个深链接共享一个共同的前缀。
您还可以查看airbnb的DeepLinkDispatch库,在允许排除特定的URL看来是这样。
发布于 2017-01-02 07:34:33
如果我正确地理解了您的问题,您希望从某个URL列表中排除特定的URL。你试过的是个好办法。
正如您所说的,android:pathPattern不理解复杂的regex模式。
我认为解决问题的唯一方法是更改您想省略的URL。更改主机或该URL的一部分,或将名称example.com更改为,例如,example2.com/hello/redirect/。
https://stackoverflow.com/questions/41422305
复制相似问题