[英]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.