2017-01-02 51 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

我明白你的觀點。這對我來說是最後的選擇。但在此之前,我只需要知道我可以採取哪些解決方案來解決問題。 –