added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)   
belongs to Maven artifact com.android.support:support-media-compat:28.0.0-alpha1 Summary: [Ctors](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#pubctors) \| [Methods](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#inhmethods) \| [\[Expand All\]](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#)

# NotificationCompat.MediaStyle


`
public
static


class
NotificationCompat.MediaStyle
`


`


`

`

extends https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Style


`

`


`

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

[![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#)Known Direct Subclasses [NotificationCompat.DecoratedMediaCustomViewStyle](https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.DecoratedMediaCustomViewStyle) [NotificationCompat.DecoratedMediaCustomViewStyle](https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.DecoratedMediaCustomViewStyle) Notification style for media custom views that are decorated by the system.   

*** ** * ** ***

Notification style for media playback notifications.

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

<br />

**See also:**

- `https://developer.android.com/https://developer.android.com/reference/android/app/Notification#bigContentView`

## Summary

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle#NotificationCompat.MediaStyle()() ` |
| ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle#NotificationCompat.MediaStyle(android.support.v4.app.NotificationCompat.Builder)(https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder builder) ` |

| ### Public methods ||
|---|---|
| ` static https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` | ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle#getMediaSession(android.app.Notification)(https://developer.android.com/reference/android/app/Notification.html notification) ` 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/android/support/v4/media/app/NotificationCompat.MediaStyle` `https://developer.android.com/reference/android/app/Notification.html`. |
| ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle#setCancelButtonIntent(android.app.PendingIntent)(https://developer.android.com/reference/android/app/PendingIntent.html pendingIntent) ` Sets the pending intent to be sent when the cancel button is pressed. |
| ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | ` https://developer.android.com/reference/android/support/v4/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) ` 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. |
| ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle#setShowActionsInCompactView(int...)(int... actions) ` Requests up to 3 actions (by index in the order of addition) to be shown in the compact notification view. |
| ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | ` https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle#setShowCancelButton(boolean)(boolean show) ` Sets whether a cancel button at the top right should be shown in the notification on platforms before Lollipop. |

### Inherited methods

[![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#)From class `

https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Style

` `


https://developer.android.com/reference/android/app/Notification.html` `
https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Style#build()()
` `


void` `
https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Style#setBuilder(android.support.v4.app.NotificationCompat.Builder)(https://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder builder)
` [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v4-media-app/NotificationCompat.MediaStyle#)From class `

java.lang.Object

` `


Object` `
clone()
` `


boolean` `
equals(Object arg0)
` `


void` `
finalize()
` `


final

Class<?>` `
getClass()
` `


int` `
hashCode()
` `


final

void` `
notify()
` `


final

void` `
notifyAll()
` `


String` `
toString()
` `


final

void` `
wait(long arg0, int arg1)
` `


final

void` `
wait(long arg0)
` `


final

void` `
wait()
`

## Public constructors

### NotificationCompat.MediaStyle

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
NotificationCompat.MediaStyle ()
```

<br />

<br />

### NotificationCompat.MediaStyle

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
NotificationCompat.MediaStyle (NotificationCompat.Builder builder)
```

<br />

<br />

| Parameters ||
|---|---|
| `builder` | `NotificationCompat.Builder` <br /> |

## Public methods

### getMediaSession

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
MediaSessionCompat.Token getMediaSession (Notification notification)
```

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/android/support/v4/media/app/NotificationCompat.MediaStyle` `https://developer.android.com/reference/android/app/Notification.html`.

<br />

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

| 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. <br /> |

### setCancelButtonIntent

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
NotificationCompat.MediaStyle setCancelButtonIntent (PendingIntent pendingIntent)
```

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

<br />

| Parameters ||
|---|---|
| `pendingIntent` | `PendingIntent`: the intent to be sent when the cancel button is pressed <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | <br /> |

### setMediaSession

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
NotificationCompat.MediaStyle setMediaSession (MediaSessionCompat.Token token)
```

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.

<br />

| Parameters ||
|---|---|
| `token` | `MediaSessionCompat.Token` <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | <br /> |

### setShowActionsInCompactView

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
NotificationCompat.MediaStyle setShowActionsInCompactView (int... actions)
```

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

<br />

| Parameters ||
|---|---|
| `actions` | `int`: the indices of the actions to show in the compact notification view <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | <br /> |

### setShowCancelButton

added in [version 26.1.0](https://developer.android.com/topic/libraries/support-library/revisions)

```
NotificationCompat.MediaStyle setShowCancelButton (boolean show)
```

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.

<br />

| Parameters ||
|---|---|
| `show` | `boolean`: whether to show a cancel button <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle` | <br /> |

-

  ## Classes

  - [NotificationCompat](https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat)
  - [NotificationCompat.DecoratedMediaCustomViewStyle](https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.DecoratedMediaCustomViewStyle)
  - [NotificationCompat.MediaStyle](https://developer.android.com/reference/android/support/v4/media/app/NotificationCompat.MediaStyle)