我正在尝试向我的应用添加深层链接,我正在使用 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>
谁能帮我理解为什么它可以在模拟器上运行而不是在真实设备上运行?
最佳答案
在包页面中,作者说“通常你会检查 getInitialLink
并听取更改。”可能是这样的情况,当您在 android 模拟器上尝试时,您的应用程序在后台,但当您尝试使用真实设备时,应用程序未打开。试用作者获得的示例代码,如果问题仍然存在,请在他的 github 页面中报告该问题。
这些链接的问题在于,只需拥有 intent-filter
即使您没有任何 Dart 代码,该应用程序也会打开。因此,当应用程序启动时可能会有些困惑,但未显示数据。我会尝试getInitialLink
.
关于android - flutter 深度链接在真实设备上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66136736/