Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  
Deprecated in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# MediaNotification

*** ** * ** ***

```
open class MediaNotification
```

|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||
| ↳ | [android.media.MediaSession2Service.MediaNotification](https://developer.android.com/reference/kotlin/android/media/MediaSession2Service.MediaNotification#) |

*** ** * ** ***

> [!CAUTION]
> **This class was deprecated in API level 37.**
>
> Use the Media3 support library's `androidx.media3.session.MediaSessionService` instead.

This API is not generally intended for third party application developers. Use the [AndroidX](https://developer.android.com/jetpack/androidx.html) [Media3 session Library](https://developer.android.com/media/media3/session/control-playback) for consistent behavior across all devices.

Returned by `https://developer.android.com/reference/kotlin/android/media/MediaSession2Service#onUpdateNotification(android.media.MediaSession2)` for making session service foreground service to keep playback running in the background. It's highly recommended to show media style notification here.

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/media/MediaSession2Service.MediaNotification#MediaNotification(kotlin.Int,%20android.app.Notification)(notificationId: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, notification: https://developer.android.com/reference/kotlin/android/app/Notification.html#)` Default constructor |

| Public methods ||
|---|---|
| open [Notification](https://developer.android.com/reference/kotlin/android/app/Notification.html#) | `https://developer.android.com/reference/kotlin/android/media/MediaSession2Service.MediaNotification#getNotification()()` Gets the notification. |
| open [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/android/media/MediaSession2Service.MediaNotification#getNotificationId()()` Gets the id of the notification. |

## Public constructors

### MediaNotification

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
MediaNotification(
    notificationId: Int, 
    notification: Notification)
```

Default constructor

| Parameters ||
|---|---|
| `notificationId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): notification id to be used for `https://developer.android.com/reference/kotlin/android/app/NotificationManager.html#notify(kotlin.Int,%20android.app.Notification)`. |
| `notification` | [Notification](https://developer.android.com/reference/kotlin/android/app/Notification.html#): a notification to make session service run in the foreground. Media style notification is recommended here. This value cannot be `null`. |

## Public methods

### getNotification

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun getNotification(): Notification
```

**Deprecated:** *Deprecated in Java.*

Gets the notification.

| Return ||
|---|---|
| `https://developer.android.com/reference/kotlin/android/app/Notification.html#` | the notification. This value cannot be `null`. |

### getNotificationId

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun getNotificationId(): Int
```

**Deprecated:** *Deprecated in Java.*

Gets the id of the notification.

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | the notification id |