英文:
How to navigate to a composable screen from a notification with deeplinks?
问题
我想在点击包含标题、正文和ID等数据的通知时,导航到一个组合屏幕。这个ID应该在创建路由时传递给组合屏幕。
这是我的组合屏幕导航:
object Screen : AppDestination("screen/{id}") {
fun createRoute(id: String): String {
return "screen/$id"
}
"id"是当列表中的某个项目被点击时要传递的值。
"idNotation"是我从通知中获取的ID。
如果我在调用createRoute后在深链接中获取它,我该如何将idNotation传递给路由?
我已经测试了如何将ID传递给通知的挂起意图,这部分是有效的,我只是不确定如何将它传递给路由。
英文:
I want to navigate to a composable screen when clicking on a notification that contains data like title, body, and an id. This id should be passed to the composable when the route is created.
object Screen : AppDestination("screen/{id}") {
fun createRoute(id: String): String {
return "screen/$id"
}
This is my composable screen navigation
fun NavGraphBuilder.screenGraph(
navController: NavHostController
) {
composable(
route = Screen.route,
arguments = listOf(navArgument("id") { type = NavType.StringType },
navArgument("idnotation") { type = NavType.StringType }),
deepLinks = listOf(
navDeepLink {
uriPattern = "myapp://screennavigation/idnotation={idnotation}"
}
) {
Screen(
payloadId = it.arguments?.getString("id"),
)
}
}
The "id" is the when a certain item from a list is clicked to navigate to it.
The "idNotation" is the id that i get from the notification.
How can I pass the idNotation to the route if i'm getting it in the deeplink after the route is createRoute is called?
I tested how i'm passing the Id to the intent inside a pending intent for a notification and that works, i'm getting it correctly, I'm just not sure how to pass it to the route.
答案1
得分: 2
你的深度链接是
"myapp://screennavigation/idnotation={idnotation}"
这意味着{idnotation}
占位符的值将被放入带有键idnotation
的参数中。如果你想要它填充id
字段(以匹配你的路由和arguments
列表),那么你将想使用{id}
:
uriPattern = "myapp://screennavigation/idnotation={id}"
英文:
Your deep link is
"myapp://screennavigation/idnotation={idnotation}"
Which means that the value of the {idnotation}
placeholder will be put into your arguments with the key idnotation
. If you want it to instead fill in the id
field (to match your route and arguments
list), then you'll want to use {id}
:
uriPattern = "myapp://screennavigation/idnotation={id}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论