如何从通知导航到片段? Android 科特林
How to navigate to a fragment from Notification? Android Kotlin
收到通知后,我想打开我的应用程序并导航到 Details 片段,因为我正在使用来自 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())
An explicit deep link is a single instance of a deep link that uses a PendingIntent
to take users to a specific location within your app. You might surface an explicit deep link as part of a notification or an app widget, for example.
You can use the NavDeepLinkBuilder
class to construct a PendingIntent
val pendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent()
有了 PendingIntent
,您可以使用 setContentIntent()
:
将其附加到您的通知中
builder.setContentIntent(pendingIntent)
收到通知后,我想打开我的应用程序并导航到 Details 片段,因为我正在使用来自 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())
An explicit deep link is a single instance of a deep link that uses a
PendingIntent
to take users to a specific location within your app. You might surface an explicit deep link as part of a notification or an app widget, for example.
You can use the
NavDeepLinkBuilder
class to construct aPendingIntent
val pendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.android)
.setArguments(args)
.createPendingIntent()
有了 PendingIntent
,您可以使用 setContentIntent()
:
builder.setContentIntent(pendingIntent)