senzacionale
senzacionale

Reputation: 20916

How to cancel Notification.FLAG_FOREGROUND_SERVICE

Let's suppose you wish to show a Notification with the foreground service flag, and use nm to display it:

Notification notification = new Notification(...);
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE
nm.notify(SOME_ID, notification);

The notification will appear. However, removing it is difficult, because this doesn't appear to do anything:

nm.cancel(SOME_ID);

how to cancel this Notification? stopForeground is not a solution because i amnot in the service.

Upvotes: 1

Views: 1716

Answers (2)

Javier
Javier

Reputation: 1695

The solution its After removing FLAG_FOREGROUND_SERVICE and using only 0 or FLAG_ONGOING_EVENT, the notification could be made cancelable or un-cancelable - respectively. Works for me, the answer i found this was helpfull Switching Android notification from FLAG_ONGOING_EVENT to cancelable

Upvotes: 0

CommonsWare
CommonsWare

Reputation: 1007296

is there any solution?

If this issue is to be believed, then no, other than having a service call stopForeground(). You can send a command to your service via startService() so it can call stopForeground(). Or, you can create a tiny dedicated Service that simply calls stopForeground() and stopSelf() from onStartCommand(), just for getting rid of this notification.

Upvotes: 2

Related Questions