【问题标题】:How to navigate to a fragment from Notification? Android Kotlin如何从通知导航到片段?安卓科特林
【发布时间】:2020-08-05 17:32:34
【问题描述】:

收到通知后,我想打开我的应用程序并导航到详细信息片段,因为我正在使用来自 jetpack 的导航组件,但我不知道如何实现它?

这是我的通知服务代码

val intent = Intent(this, DetailedFragment::class.java) 

    val builder = NotificationCompat.Builder(this, "100")
        .setSmallIcon(R.drawable.ic_notification)
        .setContentTitle(rm.data["title"])
        .setContentText(rm.data["body"])
        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
        .setCustomContentView(nmrv)
        .setCustomBigContentView(exrv)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setStyle(NotificationCompat.DecoratedCustomViewStyle())

    val manager = NotificationManagerCompat.from(this).notify(100, builder.build())

【问题讨论】:

    标签: android kotlin firebase-cloud-messaging android-notifications


    【解决方案1】:

    根据the documentation

    显式深层链接是深层链接的单个实例,它使用PendingIntent 将用户带到您应用中的特定位置。例如,您可能会将显式深层链接作为通知或应用小部件的一部分显示。

    您可以使用NavDeepLinkBuilder 类来构造PendingIntent

    val pendingIntent = NavDeepLinkBuilder(context)
        .setGraph(R.navigation.nav_graph)
        .setDestination(R.id.android)
        .setArguments(args)
        .createPendingIntent()
    

    使用PendingIntent,您可以使用setContentIntent() 将其附加到您的通知中:

    builder.setContentIntent(pendingIntent)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      • 1970-01-01
      相关资源
      最近更新 更多