public class

MediaStyleNotificationHelper.MediaStyle

extends NotificationCompat.Style

 java.lang.Object

androidx.core.app.NotificationCompat.Style

↳androidx.media3.session.MediaStyleNotificationHelper.MediaStyle

Subclasses:

MediaStyleNotificationHelper.DecoratedMediaCustomViewStyle

Overview

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(android.graphics.Bitmap) 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 MediaStyleNotificationHelper.MediaStyle.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, 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()
     .setSmallIcon(androidx.media3.R.drawable.media3_notification_small_icon)
     .setContentTitle("Track title")
     .setContentText("Artist - Album")
     .setLargeIcon(albumArtBitmap)
     .setStyle(new MediaStyleNotificationHelper.MediaStyle(mySession))
     .build();
 

Summary

Fields
from NotificationCompat.StylemBuilder
Constructors
publicMediaStyle(MediaSession session)

Creates a new instance with a MediaSession to this Notification to provide additional playback information and control to the SystemUI.

Methods
public voidapply(NotificationBuilderWithBuilderAccessor builder)

Applies the compat style data to the framework Notification in a backwards compatible way.

public static SessionTokengetSessionToken(Notification notification)

Extracts a SessionToken from the extra values in the MediaStyleNotificationHelper.MediaStyle notification.

public MediaStyleNotificationHelper.MediaStylesetCancelButtonIntent(PendingIntent pendingIntent)

public MediaStyleNotificationHelper.MediaStylesetRemotePlaybackInfo(java.lang.CharSequence deviceName, int iconResource, PendingIntent chipIntent)

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.

public MediaStyleNotificationHelper.MediaStylesetShowActionsInCompactView(int[] actions[])

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

public MediaStyleNotificationHelper.MediaStylesetShowCancelButton(boolean show)

from NotificationCompat.StyleaddCompatExtras, applyStandardTemplate, build, buildIntoRemoteViews, clearCompatExtraKeys, createColoredBitmap, displayCustomViewInline, extractStyleFromNotification, getClassName, makeBigContentView, makeContentView, makeHeadsUpContentView, restoreFromCompatExtras, setBuilder
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public MediaStyle(MediaSession session)

Creates a new instance with a MediaSession to this Notification to provide additional playback information and control to the SystemUI.

Methods

public static SessionToken getSessionToken(Notification notification)

Extracts a SessionToken from the extra values in the MediaStyleNotificationHelper.MediaStyle notification.

Parameters:

notification: The notification to extract a MediaSession from.

Returns:

The SessionToken in the notification if it contains, null otherwise.

public MediaStyleNotificationHelper.MediaStyle setShowActionsInCompactView(int[] actions[])

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

Parameters:

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

public MediaStyleNotificationHelper.MediaStyle setShowCancelButton(boolean show)

Deprecated: This method is a no-op and usages can be safely removed. There is no recommended alternative (it was previously only operational on API < 21).

public MediaStyleNotificationHelper.MediaStyle setCancelButtonIntent(PendingIntent pendingIntent)

Deprecated: This method is a no-op and usages can be safely removed. There is no recommended alternative (it was previously only operational on API < 21).

public MediaStyleNotificationHelper.MediaStyle setRemotePlaybackInfo(java.lang.CharSequence deviceName, int iconResource, PendingIntent chipIntent)

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.

Most apps should integrate with android.media.MediaRouter2 instead. This method is only 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.

Also note that this method is a no-op when running on API 33 or lower.

Parameters:

deviceName: The name of the remote device to display.
iconResource: Icon resource, of size 12, representing the device.
chipIntent: 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 or it will be ignored.

public void apply(NotificationBuilderWithBuilderAccessor builder)

Applies the compat style data to the framework Notification in a backwards compatible way. All other data should be stored within the Notification's extras.