Skip to content

Most visited

Recently visited

navigation

NotificationCompat.MediaStyle

public static class NotificationCompat.MediaStyle
extends NotificationCompat.MediaStyle

java.lang.Object
   ↳ android.support.v4.app.NotificationCompat.Style
     ↳ android.support.v4.media.app.NotificationCompat.MediaStyle
       ↳ android.support.v7.app.NotificationCompat.MediaStyle


This class was deprecated in API level 26.0.0.
Use NotificationCompat.MediaStyle.

Notification style for media playback notifications. In the expanded form, bigContentView, up to 5 NotificationCompat.Actions specified with addAction will be shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to setLargeIcon() will be treated as album artwork. Unlike the other styles provided here, MediaStyle can also modify the standard-size contentView; 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 setStyle(NotificationCompat.Style) like so:

 Notification noti = new NotificationCompat.Builder()
     .setSmallIcon(R.drawable.ic_stat_player)
     .setContentTitle("Track title")
     .setContentText("Artist - Album")
     .setLargeIcon(albumArtBitmap))
     .setStyle(new NotificationCompat.MediaStyle()
         .setMediaSession(mySession))
     .build();
 

Summary

Public constructors

NotificationCompat.MediaStyle()

This constructor was deprecated in API level 26.0.0. Use #MediaStyle()

NotificationCompat.MediaStyle(NotificationCompat.Builder builder)

This constructor was deprecated in API level 26.0.0. Use #MediaStyle(android.support.v4.app.NotificationCompat.Builder)

Public methods

NotificationCompat.MediaStyle setCancelButtonIntent(PendingIntent pendingIntent)

This method was deprecated in API level 26.0.0. Use #setCancelButtonIntent(PendingIntent)

NotificationCompat.MediaStyle setMediaSession(MediaSessionCompat.Token token)

This method was deprecated in API level 26.0.0. Use #setMediaSession(MediaSessionCompat.Token)

NotificationCompat.MediaStyle setShowActionsInCompactView(int... actions)

This method was deprecated in API level 26.0.0. Use #setShowActionsInCompactView(int...)

NotificationCompat.MediaStyle setShowCancelButton(boolean show)

This method was deprecated in API level 26.0.0. Use #setShowCancelButton(boolean)

Inherited methods

From class android.support.v4.media.app.NotificationCompat.MediaStyle
From class android.support.v4.app.NotificationCompat.Style
From class java.lang.Object

Public constructors

NotificationCompat.MediaStyle

added in version 24.2.0
NotificationCompat.MediaStyle ()

This constructor was deprecated in API level 26.0.0.
Use #MediaStyle()

NotificationCompat.MediaStyle

added in version 24.2.0
NotificationCompat.MediaStyle (NotificationCompat.Builder builder)

This constructor was deprecated in API level 26.0.0.
Use #MediaStyle(android.support.v4.app.NotificationCompat.Builder)

Parameters
builder NotificationCompat.Builder

Public methods

setCancelButtonIntent

added in version 24.2.0
NotificationCompat.MediaStyle setCancelButtonIntent (PendingIntent pendingIntent)

This method was deprecated in API level 26.0.0.
Use #setCancelButtonIntent(PendingIntent)

Sets the pending intent to be sent when the cancel button is pressed. See setShowCancelButton(boolean).

Parameters
pendingIntent PendingIntent: the intent to be sent when the cancel button is pressed

Returns
NotificationCompat.MediaStyle

setMediaSession

added in version 24.2.0
NotificationCompat.MediaStyle setMediaSession (MediaSessionCompat.Token token)

This method was deprecated in API level 26.0.0.
Use #setMediaSession(MediaSessionCompat.Token)

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

Parameters
token MediaSessionCompat.Token

Returns
NotificationCompat.MediaStyle

setShowActionsInCompactView

added in version 24.2.0
NotificationCompat.MediaStyle setShowActionsInCompactView (int... actions)

This method was deprecated in API level 26.0.0.
Use #setShowActionsInCompactView(int...)

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

Parameters
actions int: the indices of the actions to show in the compact notification view

Returns
NotificationCompat.MediaStyle

setShowCancelButton

added in version 24.2.0
NotificationCompat.MediaStyle setShowCancelButton (boolean show)

This method was deprecated in API level 26.0.0.
Use #setShowCancelButton(boolean)

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 notification.

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.

Parameters
show boolean: whether to show a cancel button

Returns
NotificationCompat.MediaStyle

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)