SessionToken
class SessionToken
A token that represents an ongoing MediaSession or a service (MediaSessionService, MediaLibraryService, or
androix.media.MediaBrowserServiceCompat). If it represents a service, it may not be ongoing.
This may be passed to apps by the session owner to allow them to create a MediaController or a MediaBrowser to communicate with the session.
It can also be obtained by getAllServiceTokens.
Summary
Nested types |
|---|
@DocumentedTypes of |
Constants |
|
|---|---|
const Int |
|
const Int |
Type for |
const Int |
TYPE_SESSION = 0Type for |
const Int |
Type for |
const Int |
Unknown |
const Int |
UNKNOWN_SESSION_VERSION = 1000000Unknown |
Public constructors |
|---|
SessionToken(context: Context!, serviceComponent: ComponentName!)Creates a token for |
Public functions |
|
|---|---|
java-static ListenableFuture<SessionToken!>! |
createSessionToken(context: Context!, token: MediaSession.Token!)Creates a token from a platform |
java-static ListenableFuture<SessionToken!>! |
@UnstableApiCreates a token from a platform |
java-static ListenableFuture<SessionToken!>! |
@UnstableApiCreates a token from a platform |
java-static ListenableFuture<SessionToken!>! |
@UnstableApiCreates a token from a platform |
Boolean |
|
java-static SessionToken! |
@UnstableApiRestores a |
java-static ImmutableSet<SessionToken!>! |
getAllServiceTokens(context: Context!)Returns an |
Bundle! |
Returns the extra |
Int |
Returns the interface version of the session or |
String! |
Returns the package name of the session |
String! |
Returns the service name of the session. |
Int |
Returns the library version of the session, |
Int |
Returns the type of this token. |
Int |
getUid()Returns the UID of the session process, or |
Int |
hashCode() |
Bundle! |
|
String! |
toString() |
Constants
PLATFORM_SESSION_VERSION
const val PLATFORM_SESSION_VERSION = 0: Int
Session version for a platform android.media.session.MediaSession or legacy
android.support.v4.media.session.MediaSessionCompat.
UNKNOWN_INTERFACE_VERSION
@UnstableApi
const val UNKNOWN_INTERFACE_VERSION = 0: Int
Unknown interface version for a MediaSession that isn't connected yet, for an older session that didn't publish its interface version, for a platform android.media.session.MediaSession or for a legacy
android.support.v4.media.session.MediaSessionCompat.
Note: Use getConnectedToken to obtain the version after connecting a controller.
UNKNOWN_SESSION_VERSION
const val UNKNOWN_SESSION_VERSION = 1000000: Int
Unknown session version for a MediaSession that isn't connected yet.
Note: Use getConnectedToken to obtain the version after connecting a controller.
Public constructors
SessionToken
SessionToken(context: Context!, serviceComponent: ComponentName!)
Creates a token for MediaController or MediaBrowser to connect to one of MediaSessionService, MediaLibraryService, or
androidx.media.MediaBrowserServiceCompat.
| Parameters | |
|---|---|
context: Context! |
The context. |
serviceComponent: ComponentName! |
The component name of the service. |
Public functions
createSessionToken
java-static fun createSessionToken(context: Context!, token: MediaSession.Token!): ListenableFuture<SessionToken!>!
Creates a token from a platform Token.
| Parameters | |
|---|---|
context: Context! |
A |
token: MediaSession.Token! |
The platform |
| Returns | |
|---|---|
ListenableFuture<SessionToken!>! |
A |
createSessionToken
@UnstableApi
java-static fun createSessionToken(context: Context!, token: Parcelable!): ListenableFuture<SessionToken!>!
Creates a token from a platform Token or
android.support.v4.media.session.MediaSessionCompat.Token.
| Parameters | |
|---|---|
context: Context! |
A |
token: Parcelable! |
The |
| Returns | |
|---|---|
ListenableFuture<SessionToken!>! |
A |
createSessionToken
@UnstableApi
java-static fun createSessionToken(
context: Context!,
token: MediaSession.Token!,
completionLooper: Looper!
): ListenableFuture<SessionToken!>!
Creates a token from a platform Token.
| Parameters | |
|---|---|
context: Context! |
A |
token: MediaSession.Token! |
The platform |
completionLooper: Looper! |
The |
| Returns | |
|---|---|
ListenableFuture<SessionToken!>! |
A |
createSessionToken
@UnstableApi
java-static fun createSessionToken(
context: Context!,
token: Parcelable!,
completionLooper: Looper!
): ListenableFuture<SessionToken!>!
Creates a token from a platform Token or
android.support.v4.media.session.MediaSessionCompat.Token.
| Parameters | |
|---|---|
context: Context! |
A |
token: Parcelable! |
The |
completionLooper: Looper! |
The |
| Returns | |
|---|---|
ListenableFuture<SessionToken!>! |
A |
fromBundle
@UnstableApi
java-static fun fromBundle(bundle: Bundle!): SessionToken!
Restores a SessionToken from a Bundle.
getAllServiceTokens
java-static fun getAllServiceTokens(context: Context!): ImmutableSet<SessionToken!>!
Returns an ImmutableSet of session tokens for media session services; MediaSessionService, MediaLibraryService, and androidx.media.MediaBrowserServiceCompat regardless of their activeness.
The app targeting API level 30 or higher must include a <queries> element in their manifest to get service tokens of other apps. See the following example and this guide for more information.
<intent> <action android:name="androidx.media3.session.MediaSessionService" /> </intent> <intent> <action android:name="androidx.media3.session.MediaLibraryService" /> </intent> <intent> <action android:name="android.media.browse.MediaBrowserService" /> </intent>
getInterfaceVersion
@UnstableApi
fun getInterfaceVersion(): Int
Returns the interface version of the session or UNKNOWN_INTERFACE_VERSION.
getServiceName
fun getServiceName(): String!
Returns the service name of the session. It will be an empty string if the type is TYPE_SESSION.
getSessionVersion
fun getSessionVersion(): Int
Returns the library version of the session, UNKNOWN_SESSION_VERSION, or PLATFORM_SESSION_VERSION.
- If the session is a platform
android.media.session.MediaSessionor legacyandroid.support.v4.media.session.MediaSessionCompat, this will bePLATFORM_SESSION_VERSION. - If the token's
typeisTYPE_SESSION, this will be the same asVERSION_INTof the session. - If the token's
typeisTYPE_SESSION_SERVICEorTYPE_LIBRARY_SERVICE, this will beUNKNOWN_SESSION_VERSION. You can obtain the actual session version after a connecting a controller via theconnected tokenof typeTYPE_SESSION.
getType
@SessionToken.TokenType
fun getType(): Int
Returns the type of this token. One of TYPE_SESSION, TYPE_SESSION_SERVICE, or TYPE_LIBRARY_SERVICE.
getUid
fun getUid(): Int
Returns the UID of the session process, or INDEX_UNSET if the UID can't be determined due to missing package visibility.