I am using the Android Navigation Component from Androidx to build my pending intents to navigate.
In particular, I am using the pending intents fron Navigation to navigate from my notifications. However, there is no way to cancel the notification when the action has been clicked.
It works correctly if I click in the Notification itself because I am using setAutoCancel(true)
. However, I can't find any autoCancel
for the Notification Actions.
This is my code:
// Build Pending Intent
val statusPendingIntent = NavDeepLinkBuilder(context)
.setGraph(R.navigation.navigation)
.setDestination(R.id.status)
.createPendingIntent()
// Build Notification Action
val statusAction = NotificationCompat.Action(
R.drawable.menu_icon_status,
resources.getString(R.string.menuitem_status),
statusPendingIntent
)
// Build Notification
val notificationBuilder = NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle(title)
.setContentText(message)
.setContentIntent(someOtherIntent) // This intent cancels the notification as it has "AutoCancel"
.addAction(statusAction) // This is the notification action. If I click on it, the notification is not cancelled
.setAutoCancel(true) // AutoCancel itself, closes the notification on tap
Has anyone this issue too?