Added in API level 21

MediaStyle

open class MediaStyle : Notification.Style
kotlin.Any
   ↳ android.app.Notification.Style
   ↳ android.app.Notification.MediaStyle

Notification style for media playback notifications. In the expanded form, Notification#bigContentView, up to 5 Notification.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 Notification#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 android.media.session.MediaSession.Token using android.app.Notification.MediaStyle#setMediaSession(MediaSession.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).

Starting at Android O any notification that has a media session attached with setMediaSession(android.media.session.MediaSession.Token) will be colorized. You can opt-out of this behavior by using Notification.Builder#setColorized(boolean).

To use this style with your Notification, feed it to Notification.Builder#setStyle(android.app.Notification.Style) like so:

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

Summary

Public constructors

Public methods
open Notification.MediaStyle!

Attach a android.media.session.MediaSession.Token to this Notification to provide additional playback information and control to the SystemUI.

open Notification.MediaStyle
setRemotePlaybackInfo(deviceName: CharSequence, iconResource: Int, chipIntent: PendingIntent?)

For media notifications associated with playback on a remote device, provide device information that will replace the default values for the output switcher chip on the media control, as well as an intent to use when the output switcher chip is tapped, on devices where this is supported.

open Notification.MediaStyle!

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

Inherited functions
Inherited properties

Public constructors

MediaStyle

Added in API level 21
MediaStyle()

MediaStyle

Added in API level 21
MediaStyle(builder: Notification.Builder!)

Deprecated: use MediaStyle().

Public methods

setMediaSession

Added in API level 21
open fun setMediaSession(token: MediaSession.Token!): Notification.MediaStyle!

Attach a android.media.session.MediaSession.Token to this Notification to provide additional playback information and control to the SystemUI.

setRemotePlaybackInfo

Added in API level 34
open fun setRemotePlaybackInfo(
    deviceName: CharSequence,
    iconResource: Int,
    chipIntent: PendingIntent?
): Notification.MediaStyle

For media notifications associated with playback on a remote device, provide device information that will replace the default values for the output switcher chip on the media control, as well as an intent to use when the output switcher chip is tapped, on devices where this is supported.

This method is intended for system applications to provide information and/or functionality that would otherwise be unavailable to the default output switcher because the media originated on a remote device.
Requires android.Manifest.permission#MEDIA_CONTENT_CONTROL

Parameters
deviceName CharSequence: The name of the remote device to display This value cannot be null.
iconResource Int: Icon resource representing the device
chipIntent PendingIntent?: PendingIntent to send when the output switcher is tapped. May be null, in which case the output switcher will be disabled. This intent should open an Activity or it will be ignored.
Return
Notification.MediaStyle MediaStyle This value cannot be null.

setShowActionsInCompactView

Added in API level 21
open fun setShowActionsInCompactView(vararg actions: Int): Notification.MediaStyle!

Request 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