Stay organized with collections
Save and categorize content based on your preferences.
open class MediaNotification
This API is not generally intended for third party application developers. Use the AndroidX Media3 session Library for consistent behavior across all devices.
Returned by 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 |
Default constructor
|
Public methods |
open Notification |
Gets the notification.
|
open Int |
Gets the id of the notification.
|
Public constructors
MediaNotification(
notificationId: Int,
notification: Notification)
Default constructor
Public methods
getNotification
open fun getNotification(): Notification
Gets the notification.
Return |
Notification |
the notification This value cannot be null . |
getNotificationId
open fun getNotificationId(): Int
Gets the id of the notification.
Return |
Int |
the notification id |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# MediaSession2Service.MediaNotification\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nMediaNotification\n=================\n\n*** ** * ** ***\n\nKotlin \\|[Java](/reference/android/media/MediaSession2Service.MediaNotification \"View this page in Java\") \n\n```\nopen class MediaNotification\n```\n\n|---|-----------------------------------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [android.media.MediaSession2Service.MediaNotification](#) |\n\nThis 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.\n\nReturned by [onUpdateNotification(android.media.MediaSession2)](/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.\n\nSummary\n-------\n\n| Public constructors ||\n|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| [MediaNotification](#MediaNotification(kotlin.Int,%20android.app.Notification))`(`notificationId:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`, `notification:` `[Notification](../app/Notification.html#)`)` Default constructor |\n\n| Public methods ||\n|---------------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| open [Notification](../app/Notification.html#) | [getNotification](#getNotification())`()` Gets the notification. |\n| open [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [getNotificationId](#getNotificationId())`()` Gets the id of the notification. |\n\nPublic constructors\n-------------------\n\n### MediaNotification\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nMediaNotification(\n notificationId: Int, \n notification: Notification)\n```\n\nDefault constructor\n\n| Parameters ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `notificationId` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html): notification id to be used for [NotificationManager.notify(int, Notification)](../app/NotificationManager.html#notify(kotlin.Int,%20android.app.Notification)). |\n| `notification` | [Notification](../app/Notification.html#): a notification to make session service run in the foreground. Media style notification is recommended here. This value cannot be `null`. |\n\nPublic methods\n--------------\n\n### getNotification\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getNotification(): Notification\n```\n\nGets the notification.\n\n| Return ||\n|-------------------------------------------|-----------------------------------------------|\n| [Notification](../app/Notification.html#) | the notification This value cannot be `null`. |\n\n### getNotificationId\n\nAdded in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun getNotificationId(): Int\n```\n\nGets the id of the notification.\n\n| Return ||\n|----------------------------------------------------------------------------|---------------------|\n| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | the notification id |"]]