Android APIs
public final class

MediaSessionManager

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

Class Overview

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.

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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void addOnActiveSessionsChangedListener (MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener)

Added in API level 21

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 The listener to add.
notificationListener The enabled notification listener component. May be null.

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

Added in API level 21

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 The listener to add.
notificationListener The enabled notification listener component. May be null.
handler The handler to post events to.

public List<MediaController> getActiveSessions (ComponentName notificationListener)

Added in API level 21

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 The enabled notification listener component. May be null.
Returns
  • A list of controllers for ongoing sessions.

public void removeOnActiveSessionsChangedListener (MediaSessionManager.OnActiveSessionsChangedListener listener)

Added in API level 21

Stop receiving active sessions updates on the specified listener.

Parameters
listener The listener to remove.