- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当用户在我们的应用程序中输入地理围栏时,我们会向他们显示有关该区域的报价通知,单击该通知时,应将他们引导至名为 SingleNotification
的特定可组合屏幕.我关注了谷歌的codelab和他们的documentation但我还没有设法使导航到特定屏幕的工作。现在,点击通知或运行adb shell am start -d “eway://station_offers/date_str/www.test.com/TITLE/CONTENT” -a android.intent.action.VIEW
命令,只需打开应用程序。
该 Activity 在 list 中声明如下:
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
<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:host="station_offers"
android:scheme="eway" />
</intent-filter>
</activity>
我们的 MainNavController 类包含 NavHost,而 NavHost 又包含各种 NavGraphs。我只包括了下面的相关图表:
NavHost(
navController = navController,
startDestination = NavigationGraphs.SPLASH_SCREEN.route
) {
....
notificationsNavigation()
....
}
通知导航图定义如下:
fun NavGraphBuilder.notificationsNavigation() {
navigation(
startDestination = Screens.NOTIFICATION_DETAILS.navRoute,
route = NavigationGraphs.NOTIFICATIONS.route
) {
composable(
route = "${Screens.NOTIFICATION_DETAILS.navRoute}/{date}/{imageUrl}/{title}/{content}",
arguments = listOf(
navArgument("date") { type = NavType.StringType },
navArgument("imageUrl") { type = NavType.StringType },
navArgument("title") { type = NavType.StringType },
navArgument("content") { type = NavType.StringType }
),
deepLinks = listOf(navDeepLink {
uriPattern = "eway://${Screens.NOTIFICATION_DETAILS.navRoute}/{date}/{imageUrl}/{title}/{content}"
})
) { backstackEntry ->
val args = backstackEntry.arguments
SingleNotification(
date = args?.getString("date")!!,
imageUrl = args.getString("imageUrl")!!,
title = args.getString("title")!!,
description = args.getString("content")!!
)
}
}
}
Screes.NOTIFICATION_DETAILS.navRoute
对应于
notification_details
的值.
val deepLinkIntent = Intent(
Intent.ACTION_VIEW,
"eway://station_offers/${
offer.date
}/${
offer.image
}/${offer.title}/${offer.content}".toUri(),
context,
MainActivity::class.java
)
val deepLinkPendingIntent: PendingIntent =
TaskStackBuilder.create(context!!).run {
addNextIntentWithParentStack(deepLinkIntent)
getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)!!
}
showNotification(offer.title, offer.content, deepLinkPendingIntent)
我无法弄清楚我在这里缺少什么。
最佳答案
更新 :请参阅下面@curioustechizen 的答案以获取实际解决方案,而不是这种解决方法!
好吧,经过大量测试并逐行运行谷歌相关代码实验室的解决方案,我想出了如何让它工作。
首先,它看起来像 host
我们在 AndroidManifest.xml 中为 <data>
定义的 Intent 过滤器的标签需要很多可组合目的地的路线。所以在我的例子中,它被定义为:
<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:host="notification_details"
android:scheme="eway" />
</intent-filter>
其次,深层链接的 uri 模式应该与可组合的路由格式相匹配。在这种情况下,由于可组合的路由定义为
route = "${Screens.NOTIFICATION_DETAILS.navRoute}/{date}/{imageUrl}/{title}/{content}"
,正确的深层链接
uriPattern
, 将会 :
deepLinks = listOf(navDeepLink {
uriPattern =
"eway://${Screens.NOTIFICATION_DETAILS.navRoute}/{date}/{imageUrl}/{title}/{content}"
})
此外,可组合目的地似乎必须在
NavHost
中声明。本身而不是在 NavGraph 中。最初如您所见,我认为系统将能够通过嵌套的 NavGraph 找到目的地,但它不能(抛出一个相对异常),所以我得出结论必须以这种方式完成(如在代码实验室中完成)。如果我错了,请纠正我!
val uri
相应地在我的 GeofenceBroadcastReceiver 中定义。现在看起来像这样:
val uri = "eway://${Screens.NOTIFICATION_DETAILS.navRoute}/${
offer.date.replace(
"/",
"@"
)
}/${
offer.image.replace(
"/",
"@"
)
}/${offer.title}/${offer.content.replace("/", "@")}".toUri()
回顾一下,就我的理解而言,这些是似乎可以解决这个问题的步骤:
android:host
应该匹配目标可组合的路由,最后是 scheme://host/....
,如果您遵循数字 2,则应该没问题)关于android - 使用 Jetpack Compose 的深层链接导航到可组合项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72316892/
有没有一种简单的方法可以在 compose 中删除开关的内部填充? 我尝试在其修饰符中提供 0.dp,但它并没有摆脱内部填充 Switch( modifier = Modifier
我正在使用底部导航栏,每个菜单都会将用户导航到特定的可组合屏幕。我使用导航库来管理它们之间的导航。 我为所有可组合项使用一个通用的 ViewModel。我在其中一个可组合项中使用惰性列,当我通过单击底
我在撰写屏幕中有一个 TextField 和一个 ModalDrawer。我想在用户打开抽屉时关闭软键盘,但我一直无法弄清楚如何。在 ModalDrawer afaik 中没有触发 onOpened
我一直在搜索文档,但找不到确认。有谁知道navigation和 compose来自 Android Jetpack 的组件彼此兼容吗? 我知道Jetpack Compose尚未准备好生产,仅处于开发人
我正在尝试将我的应用程序更新为新的撰写版本,但它给了我一个我不知道如何修复的错误。当我运行时,错误仍然存在于我的运行中。我的旧项目正常工作,但我想要的是更改版本,如果有人可以帮助我,我将不胜感激
我有这样的用户界面: val scrollState = rememberScrollState() Column( modifier = Modifier
有没有办法在 Compose 中的列表(列/行)更改上获得动画效果,看起来类似于带有 setItemAnimator 的 recyclerview 动画? 最佳答案 目前没有办法用 LazyColum
我想隐藏状态栏,我已经使用伴奏库做到了这一点: val systemUiController = rememberSystemUiController() systemUiController.isS
我想隐藏状态栏,我已经使用伴奏库做到了这一点: val systemUiController = rememberSystemUiController() systemUiController.isS
使用 Android View,我可以像这样将焦点移动到 View: fun View.requestAccessibilityFocus() { requestFocus() sen
我正在尝试在我的 Android 应用程序中使用 Jetpack Compose 播放视频。要使用 ExoPlayer 进行流式传输,但我真的不明白如何实现全屏按钮,有什么建议吗? @Composab
通常可以使用修饰符将不同的形状分配给可组合项,但在此可组合项中没有这样做。 我希望图像中标记的部分是一个圆圈 你可以在下面看到我写的代码 @Composable fun StandardCheckbo
Jetpack compose 提供了很多 Material 组件,如 TextField 等。 然而,要构建类似文件编辑器的东西,可以使用什么样的组件来支持多行文本任意长的文本操作,如选择文本、剪切
我们可以使用 Scaffold 在 JetpackCompose 中使用抽屉导航如下 Scaffold( drawerContent = { Text(text ="Drawer") } )
对不起,我几乎不会说英语。 机器翻译: 如何为 Jetpack Compose 设置阴影颜色? 我可以设置阴影,但它们很难看。 Jetpack Compose 代码: Surface( mod
我正在开发一个小型 jetpack-compose 演示聊天应用程序。所以我需要在底部有一个带有 TextField 和一个要发送的按钮的栏,就像在 WhatsApp 中一样......我认为最好使用
我正在 Jetpack Compose Desktop 中创建一个应用程序,它将接受用户输入,在用户重新打开应用程序后,输入值应该在那里。我的意思是,在用户重新打开应用程序后,用户给定的数据应该在那里
描述 在 SnackbarHostState 上调用 showSnackbar 并传递 duration 参数不会关闭 Snackbar。协程似乎无限期暂停。 重现步骤: val snackbarHo
谁能建议如何在 Jetpack Compose Navigation 的不同部分共享 ViewModel? 根据文档,viewModels 通常应该在使用事件范围的不同组合函数中共享,但如果在导航内部
我想在相机预览上方创建一个半透明图层,如下所示: 我在我的应用程序中完成了相机预览,我想要的只是在预览上有一个半透明的图层,带有剪裁的卡片形状,如图所示(带有圆角)。 所以:全屏相机预览,上面有一个全
我是一名优秀的程序员,十分优秀!