简体   繁体   中英

Switching Android notification from FLAG_ONGOING_EVENT to cancelable

I have an ongoing task and after it finishes, I want the notification to become cancelable.

For that, I create a new notification with notification.flags as zero, but the notification keeps being un -cancelable.

Apparently, FLAG_FOREGROUND_SERVICE prevented the notification from turning into cancelable, even after reseting the flags.

After removing FLAG_FOREGROUND_SERVICE and using only 0 or FLAG_ONGOING_EVENT , the notification could be made cancelable or un-cancelable - respectively.

Please take a look here : Android update notification

In short what you will do is this:

  • Create your notification first time and assign a notification ID to it.
  • Once your service is done executing create a new cancelable notification with the same id
  • fire that notification, it should make the previous notification cancelable .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM