Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Ctors](https://developer.android.com/reference/android/media/MediaSession2Service.MediaNotification#pubctors) \| [Methods](https://developer.android.com/reference/android/media/MediaSession2Service.MediaNotification#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/media/MediaSession2Service.MediaNotification#inhmethods)

# MediaSession2Service.MediaNotification

*** ** * ** ***


`
public
static


class
MediaSession2Service.MediaNotification
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.media.MediaSession2Service.MediaNotification |

<br />

*** ** * ** ***


**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)
[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/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/android/media/MediaSession2Service.MediaNotification#MediaNotification(int,%20android.app.Notification)(int notificationId, https://developer.android.com/reference/android/app/Notification notification) ` Default constructor |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/Notification` | ` https://developer.android.com/reference/android/media/MediaSession2Service.MediaNotification#getNotification()() ` Gets the notification. |
| ` int` | ` https://developer.android.com/reference/android/media/MediaSession2Service.MediaNotification#getNotificationId()() ` Gets the id of the notification. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Public constructors

### MediaNotification

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

```
public MediaNotification (int notificationId, 
                Notification notification)
```

Default constructor

<br />

| Parameters ||
|---|---|
| `notificationId` | `int`: notification id to be used for `https://developer.android.com/reference/android/app/NotificationManager#notify(int,%20android.app.Notification)`. <br /> |
| `notification` | `Notification`: a notification to make session service run in the foreground. Media style notification is recommended here. This value cannot be `null`. <br /> |

## Public methods

### getNotification

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

```
public Notification getNotification ()
```

Gets the notification.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Notification` | the notification. This value cannot be `null`. <br /> |

### getNotificationId

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

```
public int getNotificationId ()
```

Gets the id of the notification.

<br />

| Returns ||
|---|---|
| `int` | the notification id <br /> |