# 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)

*** ** * ** ***


```
class NotificationCompat.MediaStyle : NotificationCompat.Style
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.core.app.NotificationCompat.Style](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style) ||
|   | ↳ | [androidx.media.app.NotificationCompat.MediaStyle](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle) |

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

|---|---|
| `https://developer.android.com/reference/kotlin/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/kotlin/androidx/core/app/NotificationCompat.Action` specified with `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/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/kotlin/androidx/core/app/NotificationCompat#CATEGORY_TRANSPORT()` unless you set a different category using `https://developer.android.com/reference/kotlin/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/kotlin/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/kotlin/androidx/core/app/NotificationCompat.Builder#setStyle(androidx.core.app.NotificationCompat.Style)` like so:

```kotlin
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/kotlin/androidx/media/app/NotificationCompat.MediaStyle#MediaStyle())()` **This function is deprecated.** Deprecated in Java |
| `[MediaStyle](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#MediaStyle(androidx.core.app.NotificationCompat.Builder))(builder: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder!)` **This function is deprecated.** Deprecated in Java |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/android/support/v4/media/session/MediaSessionCompat.Token!` | `[getMediaSession](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#getMediaSession(android.app.Notification))(notification: https://developer.android.com/reference/android/app/Notification.html!)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle!` | `[setCancelButtonIntent](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setCancelButtonIntent(android.app.PendingIntent))(pendingIntent: https://developer.android.com/reference/android/app/PendingIntent.html!)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle!` | `[setMediaSession](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setMediaSession(android.support.v4.media.session.MediaSessionCompat.Token))(token: https://developer.android.com/reference/kotlin/android/support/v4/media/session/MediaSessionCompat.Token!)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresPermission(value = "android.permission.MEDIA_CONTENT_CONTROL") [setRemotePlaybackInfo](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setRemotePlaybackInfo(java.lang.CharSequence,int,android.app.PendingIntent))( deviceName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html, iconResource: @https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, chipIntent: https://developer.android.com/reference/android/app/PendingIntent.html? )` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle!` | `[setShowActionsInCompactView](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setShowActionsInCompactView(int...))(actions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle!` | `[setShowCancelButton](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setShowCancelButton(boolean))(show: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` **This function is deprecated.** Deprecated in Java |

### Inherited functions

From [androidx.core.app.NotificationCompat.Style](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style) `https://developer.android.com/reference/android/app/Notification.html?` `[build](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style#build())()`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[setBuilder](https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Style#setBuilder(androidx.core.app.NotificationCompat.Builder))(builder: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationCompat.Builder?)`

**This function 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)

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

> [!CAUTION]
> **This function 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)

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

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

## Public functions

### 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)

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

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

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

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

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/android/support/v4/media/session/MediaSessionCompat.Token!` | The `https://developer.android.com/reference/kotlin/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)

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

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

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

| Parameters |
|---|---|
| `pendingIntent: https://developer.android.com/reference/android/app/PendingIntent.html!` | 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)

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

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

Attaches a `https://developer.android.com/reference/kotlin/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")
fun [setRemotePlaybackInfo](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setRemotePlaybackInfo(java.lang.CharSequence,int,android.app.PendingIntent))(
    deviceName: CharSequence,
    iconResource: @DrawableRes Int,
    chipIntent: PendingIntent?
): NotificationCompat.MediaStyle
```

> [!CAUTION]
> **This function 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 |
|---|---|
| `deviceName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` | The name of the remote device to display. |
| `iconResource: @https://developer.android.com/reference/kotlin/androidx/annotation/DrawableRes https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Icon resource, of size 12, representing the device. |
| `chipIntent: https://developer.android.com/reference/android/app/PendingIntent.html?` | 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://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle` | MediaStyle |

### setShowActionsInCompactView

```
fun [setShowActionsInCompactView](https://developer.android.com/reference/kotlin/androidx/media/app/NotificationCompat.MediaStyle#setShowActionsInCompactView(int...))(actions: IntArray<Int>!): NotificationCompat.MediaStyle!
```

> [!CAUTION]
> **This function 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 |
|---|---|
| `actions: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!` | 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)

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

> [!CAUTION]
> **This function 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 |
|---|---|
| `show: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | whether to show a cancel button |