Skip to content Skip to sidebar Skip to footer

Android P: `notificationmanager.cancel` Does Not Work If User Has Replied To Notification

NotificationManager.cancel(id) no longer clears the notification on Android P, if you have already replied to the notification with text. Is there a way to clear a notification aft

Solution 1:

Solution is :

val builder = NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Hello!")
                .setContentText("Body!")
                .setAutoCancel(true)
                .addAction(likeAction)
                .addAction(replyAction)

just add

.setOngoing(true)

Or you can do the trick, if (you need sticky notification) -> when you need to cancel this sticky notification, you must show notification again with same id and with Ongoing = true, by default Ongoing is false.

Solution 2:

you can notify a new Notification with the same ID , then you can cancel it.

//in your NotificationActionBroadcastReceiver
notificationManager.notify(ID , newNotification());//the same ID

yourHandler.postDelayed(newRunnable(){
                @Overridepublicvoidrun() {
                    notificationManager.cancel(ID);//the same ID
                }
} , 500);

Post a Comment for "Android P: `notificationmanager.cancel` Does Not Work If User Has Replied To Notification"