使用Android导航控制器组件单击推送通知消息后,如何移动到某个片段目标?

问题描述

所以我使用Firebase云消息发送了一个推送通知。收到数据有效负载后,我将使用以下代码显示推送通知

class MyFirebaseMessagingService : FirebaseMessagingService() {

    lateinit var notificationManager: NotificationManagerCompat


    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        super.onMessageReceived(remoteMessage)

        val notificationMessage = NotificationKM(remoteMessage)
        displayNotification(notificationMessage)


    }

    private fun displayNotification(notificationMessage: NotificationKM) {

        val intent = Intent(this,MainActivity::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        val landingPageIntent = PendingIntent.getActivity(this,intent,0)

        var notification = NotificationCompat.Builder(this,channel)
            .setSmallIcon(R.drawable.ic_stat_ic_notification)
            .setContentTitle(notificationMessage.title)
            .setContentText(notificationMessage.body)
            .setContentIntent(landingPageIntent)
            .setAutoCancel(true)
            .setOnlyAlertOnce(true)

        val build = notification.build()
        notificationManager.notify(1,build)




    }
    


}

我想让用户单击该通知,然后将该用户发送到这样的收件箱目标片段中

enter image description here

这是我主要活动中的导航控制器代码

class MainActivity : AppCompatActivity(),NavController.OnDestinationChangedListener {

    private lateinit var navController : NavController
   
    companion object {

        // set up the top hierarchy destination
        val appBarConfiguration = AppBarConfiguration(setOf(
            R.id.destination_home,R.id.destination_search,R.id.destination_user_control_container,R.id.destination_create_event,R.id.destination_inbox)
        )

    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        
        navController = Navigation.findNavController(this,R.id.nav_host_fragment)

        bottom_nav.setupWithNavController(navController)

        navController.addOnDestinationChangedListener(this)
        



    }

   
    override fun onDestinationChanged(controller: NavController,destination: NavDestination,arguments: Bundle?) {

       // some code here

    }



}

那么如何使用jetpack导航控制器组件来做到这一点?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...