簡體   English   中英

Android - 深層鏈接並不適用於所有情況和所有瀏覽器

[英]Android - Deep Linking doesn't work in all cases and on all browsers

我為我的一個活動創建了一個intent過濾器,以便能夠通過深層鏈接啟動它:

     <activity
        android:name="com.myapp.activities.LoginActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:host="myserver.com"
                android:pathPrefix="/product/"
                android:scheme="https" />
            <data
                android:host="www.myserver.com"
                android:pathPrefix="/product/"
                android:scheme="https" />
        </intent-filter>
    </activity>

大多數一切正常。 當我從任何電子郵件客戶端,whatsapp消息或推文中點擊這些鏈接,在應用選擇器對話框中選擇任何瀏覽器時,它會識別我的意圖過濾器並打開正確的活動。 這意味着我的意圖過濾器已定義好了。

但是......在某些情況下,我需要從設備的日歷或HTMLViewer中單擊這些鏈接。 在這些情況下, 當我選擇股票瀏覽器時,我的應用程序不會打開。 它只是打開帶有URL地址的瀏覽器。 當我選擇設備的股票瀏覽器時,就會發生這種情況。 當我選擇其他瀏覽器(例如Chrome)時,應用程序會正確打開。 知道為什么會這樣嗎? 或者如何在所有情況下啟用深層鏈接?

2個重要說明:

  1. 我現在在Galaxy S3上測試這個。 我知道Galaxy設備上的瀏覽器本身並不被認為是“庫存”。 我仍然希望找到適用於所有設備的解決方案。

  2. 深層鏈接的url地址是在瀏覽器端運行javascript的實際地址。 對於未在用戶設備上安裝應用程序的情況,它會將其重定向到Play商店。 我這樣說是因為如果他們可以解決這個問題,我也會對服務器端解決方案開放。 我看到了這個問題,但那里的答案對我不起作用。

無論如何,我非常感謝SO社區提供的任何幫助。 這對我來說是一種痛苦(對其他人來說也是肯定的)。

謝謝。

我看不出你發布的內容有什么明顯錯誤,但是你說:

在這些情況下,當我選擇股票瀏覽器時,我的應用程序不會打開。

當您點擊鏈接時,您的應用程序是否顯示為可供選擇的選項? 如果您的過濾器匹配,它應該是一個選項嗎? 如果您選擇默認瀏覽器,我不會因為吞噬意圖而責備它。

無論如何,如果你無法使它工作,你可以使用一些客戶端網絡代碼,如果安裝了網址,則將網頁發送到應用程序,如果沒有,則將URL方案修改為您自己的自定義方案。 看到這個答案:

https://stackoverflow.com/a/8237102/1137254

然后你可以過濾兩者:

<activity
    android:name="com.myapp.activities.LoginActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="myserver.com"
            android:pathPrefix="/product/"
            android:scheme="https" />
        <data
            android:host="www.myserver.com"
            android:pathPrefix="/product/"
            android:scheme="https" />
        <data
            android:host="product"
            android:scheme="asafk" />
    </intent-filter>
</activity>

更新:我自己在galaxy s3上運行了測試,發現你的pathPrefix設置有點錯誤。 您當前的過濾器使用的網址如https://myserver.com/product/blah但不是https://myserver.com/product

所以這是你的更新意圖過濾器(注意省略了正斜杠):

 <activity
    android:name="com.myapp.activities.LoginActivity"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data
            android:host="myserver.com"
            android:pathPrefix="/product"
            android:scheme="https" />
        <data
            android:host="www.myserver.com"
            android:pathPrefix="/product"
            android:scheme="https" />
    </intent-filter>
</activity>

如果這可以解決您的問題,請告訴我。 您的用戶可能仍然選擇了錯誤的選項,所以我仍然建議遵循我的其他建議,在嘗試打開應用程序的頁面上有一些Javascript(這是非常基本但我認為它已被廣泛使用)。

希望這可以解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM