public static class NotificationCompat.MediaStyle
extends NotificationCompat.Style


Notification style for media playback notifications. In the expanded form, up to 5 actions specified with #addAction(int, CharSequence, PendingIntent) addAction will be shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to #setLargeIcon( setLargeIcon() will be treated as album artwork. Unlike the other styles provided here, MediaStyle can also modify the standard-size content view; by providing action indices to setShowActionsInCompactView(int) you can promote up to 3 actions to be displayed in the standard view alongside the usual content. Notifications created with MediaStyle will have their category set to CATEGORY_TRANSPORT unless you set a different category using setCategory(). Finally, if you attach a MediaSession.Token using setMediaSession(MediaSessionCompat.Token), the System UI can identify this as a notification representing an active media session and respond accordingly (by showing album artwork in the lockscreen, for example). To use this style with your Notification, feed it to NotificationCompat.Builder.setStyle(NotificationCompat.Style) like so:

 Notification noti = new NotificationCompat.Builder()
     .setContentTitle("Track title")
     .setContentText("Artist - Album")
     .setStyle(new NotificationCompat.MediaStyle()


Public constructors

MediaStyle(NotificationCompat.Builder builder)

Public methods

static MediaSessionCompat.Token getMediaSession(Notification notification)

Extracts a MediaSessionCompat.Token from the extra values in the NotificationCompat.MediaStyle notification.

NotificationCompat.MediaStyle setCancelButtonIntent(PendingIntent pendingIntent)

Sets the pending intent to be sent when the cancel button is pressed.

NotificationCompat.MediaStyle setMediaSession(MediaSessionCompat.Token token)

Attaches a MediaSessionCompat.Token to this Notification to provide additional playback information and control to the SystemUI.

NotificationCompat.MediaStyle setShowActionsInCompactView(int... actions)

Requests up to 3 actions (by index in the order of addition) to be shown in the compact notification view.

NotificationCompat.MediaStyle setShowCancelButton(boolean show)

Sets whether a cancel button at the top right should be shown in the notification on platforms before Lollipop.

Inherited methods

Public constructors


public MediaStyle ()


public MediaStyle (NotificationCompat.Builder builder)

builder NotificationCompat.Builder

Public methods


public static MediaSessionCompat.Token getMediaSession (Notification notification)

Extracts a MediaSessionCompat.Token from the extra values in the NotificationCompat.MediaStyle notification.

notification Notification: The notification to extract a MediaSessionCompat.Token from.

MediaSessionCompat.Token The