【发布时间】:2021-12-15 07:07:06
【问题描述】:
我想在 Jetpack Compose 的 Nav Host 中使用深层链接,并在 Compose Navigation 上关注此页面:https://developer.android.com/jetpack/compose/navigation#deeplinks
我的实现: AndroidManifest.xml:
<application ...>
<activity
...
android:allowTaskReparenting="true"
android:launchMode="singleInstance">
...
<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:scheme="https" android:host="xkcd.com" />
<data android:scheme="https" android:host="www.xkcd.com" />
</intent-filter>
</activity>
</application>
MainActivity.onCreate().setContent{}
val rootUri = "https://www.xkcd.com"
NavHost(navController = navController, startDestination = "mainView") {
composable("mainView", deepLinks = listOf(navDeepLink { uriPattern = rootUri })) {
MainContent()
}
composable(
route = "singleView/{number}",
arguments = listOf(navArgument("number") { type = NavType.IntType }),
deepLinks = listOf(navDeepLink { uriPattern = "$rootUri/{number}" })
) { backStackEntry ->
val number = backStackEntry.arguments?.getInt("number")
SingleView(number)
}
}
如果我现在点击相应的链接,应用会打开,但导航不起作用
【问题讨论】:
-
检查日志信息。可能有一个表示无法识别的路径。
-
@Johann 没有日志消息似乎与深层链接或导航有任何关系
标签: android android-jetpack-compose android-jetpack-navigation android-deep-link