open class DecoratedMediaCustomViewStyle : NotificationCompat.MediaStyle
Notification style for media custom views that are decorated by the system.
Instead of providing a media notification that is completely custom, a developer can set this style and still obtain system decorations like the notification header with the expand affordance and actions.
Use #setCustomContentView(RemoteViews)
, #setCustomBigContentView(RemoteViews)
and #setCustomHeadsUpContentView(RemoteViews)
to set the corresponding custom views to display.
To use this style with your Notification, feed it to #setStyle(androidx.core.app.NotificationCompat.Style)
like so:
Notification noti = new NotificationCompat.Builder()
.setSmallIcon(R.drawable.ic_stat_player)
.setLargeIcon(albumArtBitmap))
.setCustomContentView(contentView)
.setStyle(<b>new NotificationCompat.DecoratedMediaCustomViewStyle()</b>.setMediaSession(mySession))
.build();
If you are using this style, consider using the corresponding styles like androidx.media.R.style#TextAppearance_Compat_Notification_Media
or
in your custom views in order to get the correct styling on each platform version.
Summary
Inherited functions |
From class Style
Notification? |
build()
If this Style object has been set on a notification builder, this method will build that notification and return it. Otherwise, it will return null .
|
Unit |
setBuilder(@Nullable builder: NotificationCompat.Builder?)
Link this rich notification style with a notification builder.
|
|
From class MediaStyle
MediaSessionCompat.Token! |
getMediaSession(notification: Notification!)
Extracts a MediaSessionCompat.Token from the extra values in the MediaStyle notification .
|
NotificationCompat.MediaStyle! |
setCancelButtonIntent(pendingIntent: PendingIntent!)
Sets the pending intent to be sent when the cancel button is pressed. See .
|
NotificationCompat.MediaStyle! |
setMediaSession(token: MediaSessionCompat.Token!)
Attaches a MediaSessionCompat.Token to this Notification to provide additional playback information and control to the SystemUI.
|
NotificationCompat.MediaStyle! |
setShowActionsInCompactView(vararg actions: Int)
Requests up to 3 actions (by index in the order of addition) to be shown in the compact notification view.
|
NotificationCompat.MediaStyle! |
setShowCancelButton(show: 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 android.app.Service#startForeground, but then the service exited foreground mode via android.app.Service#stopForeground, 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.
|
|
Public constructors
<init>
DecoratedMediaCustomViewStyle()