我为我的 Kotlin 应用程序构建了一项 FCM 服务,这是一个活动和多个片段类型的应用程序。我正在使用导航图从一个片段转到下一个片段。我可以看到推送通知用于数据和通知。每个通知都有一个自定义值调用notify_type。我可以在服务中很好地看到并读取这个变量。根据notify_type值,我想打开不同的片段。我想使用导航图控制器打开。有人可以帮我弄清楚需要做什么才能从 FCM 服务打开片段吗?蒂亚!
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
remoteMessage?.let {
it.data?.let { itDT ->
Log.d(TAG, "Message data payload: $itDT")
val notifyType = itDT["notify_type"]
when (notifyType) {
"public_profile" -> {
val userId = itDT["user_id"]
//need to open public profile fragment sending user id
//would normally use this. Obviously doesn't work in a service
val navController = it.findNavController()
val action = HomeFragmentDirections.actionNavigationHomeToPublicProfileFragment(
userId
)
navController.navigate(action)
} else -> {
Log.d(TAG, "Unsupported notifyType: $notifyType")
}
}
}
it.notification?.let { …Run Code Online (Sandbox Code Playgroud) push-notification android-fragments kotlin firebase-cloud-messaging android-navigation-graph
kotlin ×1