Android: remove notification from notification bar

Viewed 239698

I have created an application and with an event I manage to add notification in android notification bar. Now I need sample how to remove that notification from notification bar on an event ??

13 Answers

A short one Liner of this is:

NotificationManagerCompat.from(context).cancel(NOTIFICATION_ID)

Or to cancel all notifications is:

NotificationManagerCompat.from(context).cancelAll()

Made for AndroidX or Support Libraries.

It will help you

private var notificationManager = NotificationManagerCompat.from(this)
notificationManager.cancel("your_notification_id")

If you start notification foreground like this

startForeground("your_notification_id",notification.build())

Then you should stop foregroundservice also

notificationManager.cancel("your_notification_id")
stopForeground(true)

Just call ID:

public void delNoti(int id) {((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(id);}
Related