0

I use BroadcastReceiver to process some data after user clicks on action button from notification.

So in order to achieve that first I build PendingIntent:

val intent = Intent(context, CustomBroadcastReceiver::class.java).apply {
    action = MY_ACTION
    // Also put some extras here like notification id.
}

val pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0)

And this is called from Service which builds and shows the notification:

NotificationCompat.Builder(this, CHANNEL_ID)
        .setContentTitle(getString(R.string.title))
        .setContentText(getString(R.string.text))
        .setSmallIcon(R.drawable.ic_notification)
        .addAction(actionIcon, actionTitle, pendingIntent)
        .setAutoCancel(true)
        .build()

Then in CustomBroadcastReceiver I'm cancelling this notification (I have notification ID from intent):

getNotificationManager().cancel(notificationId)

The problem is that notification is not dismissed, it's till on notification drawer.

I saw answers from this question, but it doesn't help - I'm using applicationContext, notificationId is correct and it's greater than 0.

Nominalista
  • 4,632
  • 11
  • 43
  • 102
  • How are you getting Notification manager in getNotificationManager().cancel(notificationId) ? – rafa Sep 30 '18 at 13:58
  • Just a thought, since you’re using NotificationCompat.Builder, have you also tried using NotificationManagerCompat do handle the cancel? – Bink Nov 19 '18 at 23:08

0 Answers0