# NotificationCompat.MediaStyle

Artifact: [androidx.media:media](https://developer.android.com/jetpack/androidx/releases/media) [View Source](https://cs.android.com/search?q=file:androidx/media/app/NotificationCompat.java+class:androidx.media.app.NotificationCompat.MediaStyle) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

*** ** * ** ***


```
public class NotificationCompat.MediaStyle extends NotificationCompat.Style
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.core.app.NotificationCompat.Style](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Style) ||
|   | ↳ | [androidx.media.app.NotificationCompat.MediaStyle](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle) |

Known direct subclasses [NotificationCompat.DecoratedMediaCustomViewStyle](https://developer.android.com/reference/androidx/media/app/NotificationCompat.DecoratedMediaCustomViewStyle)

|---|---|
| `https://developer.android.com/reference/androidx/media/app/NotificationCompat.DecoratedMediaCustomViewStyle` | **This class is deprecated.** androidx.media is deprecated. <br /> |

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> androidx.media is deprecated. Please migrate to [androidx.media3](https://developer.android.com/media/media3).

Notification style for media playback notifications.

In the expanded form, up to 5 `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Action` specified with `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder` will be shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder` 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 `https://developer.android.com/reference/androidx/media/app/NotificationCompat.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 `https://developer.android.com/reference/androidx/core/app/NotificationCompat#CATEGORY_TRANSPORT()` unless you set a different category using `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#setCategory(java.lang.String)`.

Finally, if you attach a `https://developer.android.com/reference/android/media/session/MediaSession.Token.html` using `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setMediaSession(android.support.v4.media.session.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 `https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder#setStyle(androidx.core.app.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();
```

| See also |
|---|---|
| `https://developer.android.com/reference/android/app/Notification.html#bigContentView` |   |

## Summary

| ### Public constructors |
|---|
| `[MediaStyle](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#MediaStyle())()` **This method is deprecated.** Deprecated in Java |
| `[MediaStyle](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#MediaStyle(androidx.core.app.NotificationCompat.Builder))(https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder builder)` **This method is deprecated.** Deprecated in Java |

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` | `[getMediaSession](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#getMediaSession(android.app.Notification))(https://developer.android.com/reference/android/app/Notification.html notification)` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle` | `[setCancelButtonIntent](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setCancelButtonIntent(android.app.PendingIntent))(https://developer.android.com/reference/android/app/PendingIntent.html pendingIntent)` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle` | `[setMediaSession](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setMediaSession(android.support.v4.media.session.MediaSessionCompat.Token))(https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token token)` **This method is deprecated.** Deprecated in Java |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle` | `@https://developer.android.com/reference/androidx/annotation/RequiresPermission(value = "android.permission.MEDIA_CONTENT_CONTROL") [setRemotePlaybackInfo](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setRemotePlaybackInfo(java.lang.CharSequence,int,android.app.PendingIntent))( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html deviceName, @https://developer.android.com/reference/androidx/annotation/DrawableRes int iconResource, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html chipIntent )` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle` | `[setShowActionsInCompactView](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setShowActionsInCompactView(int...))(int[] actions)` **This method is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle` | `[setShowCancelButton](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setShowCancelButton(boolean))(boolean show)` **This method is deprecated.** Deprecated in Java |

### Inherited methods

From [androidx.core.app.NotificationCompat.Style](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Style) `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/Notification.html` `[build](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Style#build())()`

**This method is deprecated.** Deprecated in Java
`void` `[setBuilder](https://developer.android.com/reference/androidx/core/app/NotificationCompat.Style#setBuilder(androidx.core.app.NotificationCompat.Builder))(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder builder)`

**This method is deprecated.** Deprecated in Java

## Public constructors

### MediaStyle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public [MediaStyle](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#MediaStyle())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

### MediaStyle

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public [MediaStyle](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#MediaStyle(androidx.core.app.NotificationCompat.Builder))(NotificationCompat.Builder builder)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

## Public methods

### getMediaSession

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public static MediaSessionCompat.Token [getMediaSession](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#getMediaSession(android.app.Notification))(Notification notification)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Extracts a `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` from the extra values in the `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle``https://developer.android.com/reference/android/app/Notification.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/app/Notification.html notification` | The notification to extract a `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` from. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` | The `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` in the `notification` if it contains, null otherwise. |

### setCancelButtonIntent

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public NotificationCompat.MediaStyle [setCancelButtonIntent](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setCancelButtonIntent(android.app.PendingIntent))(PendingIntent pendingIntent)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Sets the pending intent to be sent when the cancel button is pressed. See `https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setShowCancelButton(boolean)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent.html pendingIntent` | the intent to be sent when the cancel button is pressed |

### setMediaSession

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public NotificationCompat.MediaStyle [setMediaSession](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setMediaSession(android.support.v4.media.session.MediaSessionCompat.Token))(MediaSessionCompat.Token token)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

Attaches a `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` to this Notification to provide additional playback information and control to the SystemUI.

### setRemotePlaybackInfo

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/media#1.7.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
@RequiresPermission(value = "android.permission.MEDIA_CONTENT_CONTROL")
public @NonNull NotificationCompat.MediaStyle [setRemotePlaybackInfo](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setRemotePlaybackInfo(java.lang.CharSequence,int,android.app.PendingIntent))(
    @NonNull CharSequence deviceName,
    @DrawableRes int iconResource,
    @Nullable PendingIntent chipIntent
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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.

Also note that this method is a no-op when running on Tiramisu or less.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/CharSequence.html deviceName` | The name of the remote device to display. |
| `@https://developer.android.com/reference/androidx/annotation/DrawableRes int iconResource` | Icon resource, of size 12, representing the device. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/app/PendingIntent.html 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 Activity or it will be ignored. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle` | MediaStyle |

### setShowActionsInCompactView

```
public NotificationCompat.MediaStyle [setShowActionsInCompactView](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setShowActionsInCompactView(int...))(int[] actions)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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

| Parameters |
|---|---|
| `int[] actions` | the indices of the actions to show in the compact notification view |

### setShowCancelButton

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/media#1.1.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/media#1.8.0)

```
public NotificationCompat.MediaStyle [setShowCancelButton](https://developer.android.com/reference/androidx/media/app/NotificationCompat.MediaStyle#setShowCancelButton(boolean))(boolean show)
```

> [!CAUTION]
> **This method is deprecated.**   
> Deprecated in Java

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 `https://developer.android.com/reference/android/app/Service.html#startForeground(int, android.app.Notification)`, but then the service exited foreground mode via `https://developer.android.com/reference/android/app/Service.html#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 |
|---|---|
| `boolean show` | whether to show a cancel button |