Flutter 深层链接在浏览器中不起作用

use*_*216 11 android deep-linking dart flutter

我按照此处的建议对 Android 清单进行了更改: https ://docs.flutter.dev/development/ui/navigation/deep-linking

因此,新的元数据和配置已添加到 MainActivity 中:

<!-- Deep linking -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<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="flutterbooksample.com" />
    <data android:scheme="https" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

结果,当我按照他们所说的那样使用 adb 进行测试时:

adb shell am start -a android.intent.action.VIEW \
    -c android.intent.category.BROWSABLE \
    -d "http://flutterbooksample.com/book/1"
Run Code Online (Sandbox Code Playgroud)

我得到了我想要的:

在此输入图像描述

但是,如果我尝试http://flutterbooksample.com/book/1直接在模拟器上的浏览器中打开 url,则什么也不会发生,浏览器打开页面,并且没有提示在我的应用程序中打开 url。

我还需要做其他事情才能使其正常工作吗?

Jag*_*gaa 8

简答

您无法从网络浏览器的搜索栏中调用深层链接 URL。首先,您需要创建一个 HTML 页面。然后您可以单击该链接。它会起作用的。

更多细节

就我而言,我创建了一个带有深层链接的 HTML 文件并将其发送到我的电子邮件。

HTML 文件

<a href="myapp://test">Open my app</a>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml

<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="test"
        android:scheme="myapp" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)