Android fragments Kotlin FCM推送通知,带有导航图和1个活动应用程序

Android fragments Kotlin FCM推送通知,带有导航图和1个活动应用程序,android-fragments,kotlin,push-notification,firebase-cloud-messaging,android-navigation-graph,Android Fragments,Kotlin,Push Notification,Firebase Cloud Messaging,Android Navigation Graph,我已经为我的Kotlin应用程序构建了一个FCM服务,这是一个活动和多片段类型的应用程序。我使用导航图从一个片段到下一个片段。 我可以看到数据和通知的推送通知。每个通知都有一个自定义值调用notify\u类型。我可以在服务中很好地看到和读取此变量。 根据notify_type值,我想打开不同的片段。我想用导航图控制器打开。 有人能帮我弄清楚需要做什么才能从FCM服务中打开片段吗?蒂亚 override fun onMessageReceived(remoteMessage: RemoteMess

我已经为我的Kotlin应用程序构建了一个FCM服务,这是一个活动和多片段类型的应用程序。我使用导航图从一个片段到下一个片段。 我可以看到数据和通知的推送通知。每个通知都有一个自定义值调用notify\u类型。我可以在服务中很好地看到和读取此变量。 根据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 { itBD ->
            Log.d(TAG, "Message Notification Body: $itBD")
        }
    }
}