[英]Infinite loop with Android App Links (deep links) in Flutter
目前我們的 Flutter 應用程序和深層鏈接(或應用程序鏈接和通用鏈接)存在問題。 在 iOS 上,一切正常,但在 Android 上,我們在某些鏈接上遇到了無限循環。
該應用程序可以通過深層鏈接打開,我們可以根據這些鏈接顯示內容(我們使用的是 package uni_links2 )。 但是,應用程序中的傳出鏈接存在很大問題。
我們的應用程序有一個詳細信息頁面,此處顯示具有相同域的鏈接,但它們應該在瀏覽器中打開,而不是在應用程序中打開。 鏈接 go 指向我們無法在應用程序中處理的內容。
這些鏈接應該在應用程序中從深層鏈接打開:
像這樣的 url 應該在瀏覽器中打開:
AndroidManifest.xml
<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:scheme="http" android:host="ourdomain.com" />
<data android:scheme="http" android:host="www.ourdomain.com" />
<data android:scheme="https" />
</intent-filter>
使用url_launcher package 我可以打開 url,但它們直接被視為深層鏈接並在我們自己的應用程序中再次打開。 我還嘗試了android_intent ,並且在將 Chrome 定義為默認意圖時它正在工作。
AndroidIntent intent = AndroidIntent(
action: 'action_view',
data: url,
package: 'com.android.chrome',
);
await intent.launch();
但我不能保證用戶安裝了 Chrome。
目前我不知道如何解決這個問題。 我所知道的是我可以將整個域或路徑指定為架構。 不幸的是,我不能排除特定路徑。 另外,我不知道如何指定鏈接應該在瀏覽器中打開,而不是在我們的應用程序中打開。
你知道我該如何解決這個問題嗎? 提前致謝!
只有在默認情況下選擇應用程序作為與關聯域的鏈接的打開時,才會出現無限循環。
對於url_launcher
package,使用forceWebView
參數。
await launch('URL', forceWebView: true);
這將允許特定鏈接僅在瀏覽器中打開。 您可能還需要enableJavaScript
。
<data android:scheme="http" android:host="ourdomain.com" />
<data android:scheme="http" android:host="www.ourdomain.com" />
由於您尚未定義任何 pathPattern 或 pathPrefix,因此www.ourdomain.com
的所有鏈接都將打開您的應用程序。
要指定要包含的鏈接,您應該閱讀有關 pathPatterns 的信息,一個簡單的示例可以是
<data android:scheme="http" android:host="ourdomain.com" android:pathPattern=".*category.*"/>
鏈接 - 將在應用程序中打開
這將打開所有包含單詞類別的鏈接
https://www.ourdomain.com/category
https://www.ourdomain.com/category/abc
https://www.ourdomain.com/abc/category
https://www.ourdomain.com/abc/category/xyz
鏈接 - 不會在應用程序中打開
https://www.ourdomain.com/categry
https://www.ourdomain.com/categry/abc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.