簡體   English   中英

發送通知時如何導航到特定的可組合項

[英]How can I navigate to a specific composable when sending a notification

我想知道如何在用戶單擊通知時將用戶發送到特定的可組合項。

我的代碼是這樣的,我知道它必須在 Intent 和 PendingIntent 中,但我不知道如何,我搜索並且他們談論發送到另一個 Activity 但我想要相同的 Activity 但不同的 Composable。

fun FirNotification() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        notificationChannel = NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH)
        notificationManager.createNotificationChannel(notificationChannel)
    }
    val intent = Intent(context, MainActivity::class.java)
    val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE)

    notificationBuilder = NotificationCompat.Builder(context, channelID)
    notificationBuilder.setSmallIcon(R.drawable.ic_launcher_background)
    notificationBuilder.setContentIntent(pendingIntent)
    //notificationBuilder.addAction(R.drawable.ic_launcher_background, "OPEN", pendingIntent)
    notificationBuilder.setContentTitle(title)
    notificationBuilder.setContentText(msg)
    notificationBuilder.setOngoing(false)
    notificationBuilder.setAutoCancel(true)
    notificationManager.notify(100, notificationBuilder.build())
}

我想發送到另一個可組合項而不是主要可組合項。

我使用 putextra 解決了它:

  val intent = Intent(context, MainActivity::class.java).putExtra("screen",screen)

然后閱讀它:

val screen: String? = intent.getStringExtra("screen")
if(screen != null) {
                navController.navigate(screen)
            }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM