flutter 深度链接不适用于真实设备

Gal*_*alK 6 mobile android deep-linking dart flutter

我正在尝试向我的应用程序添加深层链接,我正在使用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();
                  }
                },
              ),
            );
          }
Run Code Online (Sandbox Code Playgroud)

和我的 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>
Run Code Online (Sandbox Code Playgroud)

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

小智 0

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

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