颤振深层链接在真实设备上不起作用

时间:2021-02-10 12:17:03

标签: android flutter dart mobile deep-linking

我正在尝试向我的应用添加深层链接,我正在使用 uni_links

我按照页面上的说明操作,在 android 模拟器上一切正常 - 我通过深层链接打开应用程序,快照有数据并返回 urlResponse,但在真实设备上,当我打开时应用通过深层链接,快照没有任何数据,返回首页。

这是我的代码:

    class MyApp extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return MaterialApp(
              debugShowCheckedModeBanner: false,
              theme: ThemeData(
                primaryColor: Colors.white,
                visualDensity: VisualDensity.adaptivePlatformDensity,
              ),
              home: StreamBuilder(
                stream: getLinksStream(),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    // our app started by configured links
                    Uri uri = Uri.parse(snapshot.data);
                    List<MapEntry<String, List<String>>> list =
                        uri.queryParametersAll.entries.toList();
                    return urlResponse(uri, list);
                  } else {
                    // our app started regularly
                    return HomePage();
                  }
                },
              ),
            );
          }

和我的 AndroidManifest.xml:

    <!-- Deep Links -->
        <intent-filter>
          <action android:name="android.intent.action.VIEW" />
          <category android:name="android.intent.category.DEFAULT" />
          <category android:name="android.intent.category.BROWSABLE" />
          <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
          <data
            android:scheme="http"
            android:host="example.com"
            android:pathPrefix="/myApp"/>
        </intent-filter>

谁能帮我理解为什么它可以在模拟器上运行而不是在真实设备上运行?

1 个答案:

答案 0 :(得分:0)

在包页面中,作者说“通常您会检查 getInitialLink 并侦听更改。”可能的情况是,当您尝试使用 android 模拟器时,您的应用程序在后台运行,但是当您尝试使用真实设备时,该应用程序未打开。试试作者得到的示例代码,如果问题仍然存在,请在他的github页面报告问题。

这些链接的问题在于,即使您没有任何 dart 代码,只要拥有 intent-filter,应用程序就会打开。所以当应用程序启动时可能会有点混乱,但没有显示数据。我会尝试getInitialLink