I want to create a Media Playback notification using the new Android L MediaStyle template. Now, I succeeded doing so perfectly well for actions like previous, play, pause, next
Adding on to @matiash's answer:
For Pre-Lollipop his answer is as needed.
notificationBuilder.setStyle(new NotificationCompat.MediaStyle().setShowCancelButton(true).setCancelButtonIntent(createPlayIntent());
For post-Lollipop:
To start a media-player notification one must have surely used startForeground()
to start the Media Service as a Foreground Service
. The problem now is that this Service
is not dismissible. EVEN IF we set the setOngoing(false)
.
The best practice followed is to make the Service dismissible in the paused state. To do that, when your Media Service receives a Pause state callback, call stopForeground(false)
. This stops the service, but keeps the notification alive. And it can now be dismissed.
Happy coding.