如何从 URL 打开 Flutter 应用程序?

54
例如,我在我的Flutter应用程序中有一个情况,当用户可以恢复他的密码。 在这种情况下,用户将收到一封电子邮件链接,我希望通过点击该链接,我的Flutter应用程序将打开并路由到特定的屏幕。

3
你可以使用 Firebase 动态链接,我写了一篇关于它的文章:https://medium.com/@diegoveloper/flutter-firebase-dynamic-link-6f1b79278ce0 - diegoveloper
@diegoveloper 谢谢!这正是我想要找的。 - Vadziec Poplavsky
有一个很好的插件可以实现这个功能,https://pub.dev/packages/uni_links 它还提供了详细的说明,告诉你如何配置iOS和Android使其正常工作(在我看来这是最难的部分);另外一个不错的信息来源是这篇博客文章 - Edoardo
6个回答

17

10

6

因此,你必须使用 动态链接

最好的解决方案是使用Firebase动态链接

Firebase动态链接的优势之一:将移动网站用户转换为原生应用用户。

使用动态链接,您可以将用户从您的移动网站无缝地转换到应用程序中相应的内容。而且,由于这些链接在应用安装过程中保留,即使是新用户也可以在您的移动网站上继续上次未完成的操作,没有任何影响。

enter image description here

另一种解决方案是切换至原生解决方案:AndroidiOS


4

如果您不想从链接中获取数据,那么您无需使用任何包来启动应用程序。

          <!-- App Link sample -->

            <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="https" android:host="myapp.flutter.com" android:pathPrefix="/success" />
                <data android:scheme="https" android:host="myapp.flutter.com" android:pathPrefix="/failure" />
            </intent-filter>

            <!-- Deep Link sample -->
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Add optional android:host to distinguish your app
                     from others in case of conflicting scheme name -->
                <data android:scheme="app" android:host="success" />
                <data android:scheme="app" android:host="failure" />
                <!-- <data android:scheme="sample" /> -->
            </intent-filter>
  • 只需复制并粘贴以下代码到AndroidManifest.xml中,然后在浏览器中启动"app://success"或"app://failure"。
  • 请记住启动"app://success"或"app://failure",而不是搜索。

2
你可以使用app_links,它支持Android应用链接、深度链接、iOS通用链接和自定义URL方案处理程序(包括桌面)适用于Android、iOS、macOS、Web和Windows。

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接