Skip to content

Most visited

Recently visited

navigation

MediaSessionManager

public final class MediaSessionManager
extends Object

java.lang.Object
   ↳ android.media.session.MediaSessionManager


Provides support for interacting with media sessions that applications have published to express their ongoing media playback state.

Use Context.getSystemService(Context.MEDIA_SESSION_SERVICE) to get an instance of this class.

See also:

Summary

Nested classes

interface MediaSessionManager.OnActiveSessionsChangedListener

Listens for changes to the list of active sessions. 

Public methods

void addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener)

Add a listener to be notified when the list of active sessions changes.This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app.

void addOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener, Handler handler)

Add a listener to be notified when the list of active sessions changes.This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app.

List<MediaController> getActiveSessions(ComponentName notificationListener)

Get a list of controllers for all ongoing sessions.

void removeOnActiveSessionsChangedListener(MediaSessionManager.OnActiveSessionsChangedListener listener)

Stop receiving active sessions updates on the specified listener.

Inherited methods

From class java.lang.Object

Public methods

addOnActiveSessionsChangedListener

added in API level 21
void addOnActiveSessionsChangedListener (MediaSessionManager.OnActiveSessionsChangedListener sessionListener, 
                ComponentName notificationListener)

Add a listener to be notified when the list of active sessions changes.This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app. You may also retrieve this list if your app is an enabled notification listener using the NotificationListenerService APIs, in which case you must pass the ComponentName of your enabled listener. Updates will be posted to the thread that registered the listener.

Parameters
sessionListener MediaSessionManager.OnActiveSessionsChangedListener: The listener to add.

This value must never be null.

notificationListener ComponentName: The enabled notification listener component. May be null.

This value may be null.

addOnActiveSessionsChangedListener

added in API level 21
void addOnActiveSessionsChangedListener (MediaSessionManager.OnActiveSessionsChangedListener sessionListener, 
                ComponentName notificationListener, 
                Handler handler)

Add a listener to be notified when the list of active sessions changes.This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app. You may also retrieve this list if your app is an enabled notification listener using the NotificationListenerService APIs, in which case you must pass the ComponentName of your enabled listener. Updates will be posted to the handler specified or to the caller's thread if the handler is null.

Parameters
sessionListener MediaSessionManager.OnActiveSessionsChangedListener: The listener to add.

This value must never be null.

notificationListener ComponentName: The enabled notification listener component. May be null.

This value may be null.

handler Handler: The handler to post events to.

This value may be null.

getActiveSessions

added in API level 21
List<MediaController> getActiveSessions (ComponentName notificationListener)

Get a list of controllers for all ongoing sessions. The controllers will be provided in priority order with the most important controller at index 0.

This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app. You may also retrieve this list if your app is an enabled notification listener using the NotificationListenerService APIs, in which case you must pass the ComponentName of your enabled listener.

Parameters
notificationListener ComponentName: The enabled notification listener component. May be null.

This value may be null.

Returns
List<MediaController> A list of controllers for ongoing sessions.

This value will never be null.

removeOnActiveSessionsChangedListener

added in API level 21
void removeOnActiveSessionsChangedListener (MediaSessionManager.OnActiveSessionsChangedListener listener)

Stop receiving active sessions updates on the specified listener.

Parameters
listener MediaSessionManager.OnActiveSessionsChangedListener: The listener to remove.

This value must never be null.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.