Language

MediaSession Constructors

Definition

Overloads

Name Description
MediaSession(Context, String)

Creates a new session.

MediaSession(Context, String, Bundle)

Creates a new session.

MediaSession(Context, String, Bundle, String)

Creates a new session with a different session owner from the calling app.

MediaSession(Context, String)

Creates a new session.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;Ljava/lang/String;)V", "")]
public MediaSession(Android.Content.Context context, string tag);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;Ljava/lang/String;)V", "")>]
new Android.Media.Session.MediaSession : Android.Content.Context * string -> Android.Media.Session.MediaSession

Parameters

context
Context

The context to use to create the session.

tag
String

A short name for debugging purposes.

Attributes

Remarks

Creates a new session. The session will automatically be registered with the system but will not be published until #setActive(boolean) setActive(true) is called. You must call #release() when finished with the session.

Note that RuntimeException will be thrown if an app creates too many sessions.

Java documentation for android.media.session.MediaSession.MediaSession(android.content.Context, java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

MediaSession(Context, String, Bundle)

Creates a new session.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)V", "", ApiSince=29)]
public MediaSession(Android.Content.Context context, string tag, Android.OS.Bundle? sessionInfo);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)V", "", ApiSince=29)>]
new Android.Media.Session.MediaSession : Android.Content.Context * string * Android.OS.Bundle -> Android.Media.Session.MediaSession

Parameters

context
Context

The context to use to create the session.

tag
String

A short name for debugging purposes.

sessionInfo
Bundle

A bundle for additional information about this session. Controllers can get this information by calling MediaController#getSessionInfo(). An IllegalArgumentException will be thrown if this contains any non-framework Parcelable objects.

Attributes

Remarks

Creates a new session. The session will automatically be registered with the system, but will not be published until #setActive(boolean) setActive(true) is called. You must call #release() when finished with the session.

The sessionInfo can include additional unchanging information about this session. For example, it can include the version of the application, or the list of the custom commands that this session supports.

Note that RuntimeException will be thrown if an app creates too many sessions.

Java documentation for android.media.session.MediaSession.MediaSession(android.content.Context, java.lang.String, android.os.Bundle).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

MediaSession(Context, String, Bundle, String)

Creates a new session with a different session owner from the calling app.

[Android.Runtime.Register(".ctor", "(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;Ljava/lang/String;)V", "", ApiSince=37)]
[Android.Runtime.RequiresPermission("android.permission.OVERRIDE_MEDIA_SESSION_OWNER")]
public MediaSession(Android.Content.Context context, string tag, Android.OS.Bundle? sessionInfo, string overridePackageName);
[<Android.Runtime.Register(".ctor", "(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;Ljava/lang/String;)V", "", ApiSince=37)>]
[<Android.Runtime.RequiresPermission("android.permission.OVERRIDE_MEDIA_SESSION_OWNER")>]
new Android.Media.Session.MediaSession : Android.Content.Context * string * Android.OS.Bundle * string -> Android.Media.Session.MediaSession

Parameters

context
Context

The context to use to create the session. This value cannot be null.

tag
String

A short name for debugging purposes. This value cannot be null.

sessionInfo
Bundle

A bundle for additional information about this session. Controllers can get this information by calling MediaController.getSessionInfo(). An IllegalArgumentException will be thrown if this contains any non-framework Parcelable objects. This value may be null.

overridePackageName
String

Package name override for the session. This value cannot be null.

Attributes

Remarks

Creates a new session with a different session owner from the calling app. The session will automatically be registered with the system, but will not be published until setActive(true) is called. You must call release() when finished with the session.

If the package of caller app is same as that of overridePackageName, prefer using MediaSession.MediaSession(Context,String,Bundle).

The sessionInfo can include additional unchanging information about this session. For example, it can include the version of the application, or the list of the custom commands that this session supports.

Note that RuntimeException will be thrown if an app creates too many sessions. Requires Manifest.permission.OVERRIDE_MEDIA_SESSION_OWNER

Android reference for android.media.session.MediaSession.MediaSession.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to