【发布时间】:2022-06-27 17:31:24
【问题描述】:
当用户在我们的应用程序中输入地理围栏时,我们会向他们显示有关该区域的报价通知,当点击该通知时,应将他们引导至名为 SingleNotification 的特定可组合屏幕。我已经关注了谷歌的codelab 和他们的documentation,但我还没有设法使导航到特定屏幕工作。现在,点击通知或运行adb shell am start -d “eway://station_offers/date_str/www.test.com/TITLE/CONTENT” -a android.intent.action.VIEW 命令,即可打开应用程序。
活动在清单中声明如下:
<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 又包含各种 NavGraph。我只包括了下面的相关图表:
NavHost(
navController = navController,
startDestination = NavigationGraphs.SPLASH_SCREEN.route
) {
....
notificationsNavigation()
....
}
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的值。
在地理围栏广播接收器中,我构造待处理的 Intent 如下:
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)
我无法弄清楚我在这里缺少什么。
【问题讨论】:
标签: android kotlin android-jetpack-compose android-deep-link