Sets whether a cancel button at the top right should be shown in the notification on
platforms before Lollipop.
Prior to Lollipop, there was a bug in the framework which prevented the developer to
make a notification dismissable again after having used the same notification as the
ongoing notification for a foreground service. When the notification was posted by
startForeground(int, Notification), but then the service exited foreground mode
via stopForeground(boolean), without removing the notification, the
notification stayed ongoing, and thus not dismissable.
This is a common scenario for media notifications, as this is exactly the service
lifecycle that happens when playing/pausing media. Thus, a workaround is provided by the
support library: Instead of making the notification ongoing depending on the playback
state, the support library provides the ability to add an explicit cancel button to the
Note that the notification is enforced to be ongoing if a cancel button is shown to
provide a consistent user experience.
Also note that this method is a no-op when running on Lollipop and later.