class SessionToken : Bundleable


A token that represents an ongoing MediaSession or a service (, MediaLibraryService, or 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 or a MediaBrowser to communicate with the session.

It can also be obtained by getAllServiceTokens.

Summary

Nested types

@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
annotation SessionToken.TokenType

Types of SessionToken.

Constants

const Bundleable.Creator<SessionToken!>!

This property is deprecated.

Use fromBundle instead.

const Int

Type for MediaLibraryService.

const Int

Type for MediaSession.

const Int

Type for MediaSessionService.

Public constructors

SessionToken(context: Context!, serviceComponent: ComponentName!)

Creates a token for MediaController or MediaBrowser to connect to one of , MediaLibraryService, or MediaBrowserServiceCompat.

Public functions

java-static ListenableFuture<SessionToken!>!
@UnstableApi
createSessionToken(
    context: Context!,
    compatToken: MediaSessionCompat.Token!
)

Creates a token from a MediaSessionCompat.Token.

java-static ListenableFuture<SessionToken!>!

Creates a token from a android.media.session.MediaSession.Token.

java-static ListenableFuture<SessionToken!>!
@UnstableApi
createSessionToken(
    context: Context!,
    compatToken: MediaSessionCompat.Token!,
    completionLooper: Looper!
)

Creates a token from a MediaSessionCompat.Token.

java-static ListenableFuture<SessionToken!>!
@UnstableApi
@RequiresApi(value = 21)
createSessionToken(
    context: Context!,
    token: MediaSession.Token!,
    completionLooper: Looper!
)

Creates a token from a android.media.session.MediaSession.Token.

Boolean
equals(obj: Any?)
java-static SessionToken!

Restores a SessionToken from a Bundle.

java-static ImmutableSet<SessionToken!>!

Returns an ImmutableSet of session tokens for media session services; MediaSessionService, MediaLibraryService, and regardless of their activeness.

Bundle!

Returns the extra Bundle of this token.

Int

Returns the interface version of the session if the type is TYPE_SESSION.

String!

Returns the package name of the session

String!

Returns the service name of the session.

Int

Returns the library version of the session if the type is TYPE_SESSION.

Int

Returns the type of this token.

Int

Returns the UID of the session process, or INDEX_UNSET if the UID can't be determined due to missing package visibility.

Int
Bundle!

Returns a Bundle representing the information stored in this object.

String!

Constants

CREATOR

@UnstableApi
const val CREATORBundleable.Creator<SessionToken!>!

Object that can restore SessionToken from a Bundle.

TYPE_LIBRARY_SERVICE

const val TYPE_LIBRARY_SERVICE = 2: Int

Type for MediaLibraryService.

TYPE_SESSION

const val TYPE_SESSION = 0: Int

Type for MediaSession.

TYPE_SESSION_SERVICE

const val TYPE_SESSION_SERVICE = 1: Int

Type for MediaSessionService.

Public constructors

SessionToken

SessionToken(context: Context!, serviceComponent: ComponentName!)

Creates a token for MediaController or MediaBrowser to connect to one of , MediaLibraryService, or MediaBrowserServiceCompat.

Parameters
context: Context!

The context.

serviceComponent: ComponentName!

The component name of the service.

Public functions

createSessionToken

@UnstableApi
java-static fun createSessionToken(
    context: Context!,
    compatToken: MediaSessionCompat.Token!
): ListenableFuture<SessionToken!>!

Creates a token from a MediaSessionCompat.Token.

Parameters
context: Context!

A Context.

compatToken: MediaSessionCompat.Token!

The MediaSessionCompat.Token.

createSessionToken

@UnstableApi
@RequiresApi(value = 21)
java-static fun createSessionToken(context: Context!, token: MediaSession.Token!): ListenableFuture<SessionToken!>!

Creates a token from a android.media.session.MediaSession.Token.

createSessionToken

@UnstableApi
java-static fun createSessionToken(
    context: Context!,
    compatToken: MediaSessionCompat.Token!,
    completionLooper: Looper!
): ListenableFuture<SessionToken!>!

Creates a token from a MediaSessionCompat.Token.

Parameters
context: Context!

A Context.

compatToken: MediaSessionCompat.Token!

The MediaSessionCompat.Token.

completionLooper: Looper!

The Looper on which the returned ListenableFuture completes. This Looper can't be used to call future.get() on the returned ListenableFuture.

createSessionToken

@UnstableApi
@RequiresApi(value = 21)
java-static fun createSessionToken(
    context: Context!,
    token: MediaSession.Token!,
    completionLooper: Looper!
): ListenableFuture<SessionToken!>!

Creates a token from a android.media.session.MediaSession.Token.

Parameters
context: Context!

A Context.

token: MediaSession.Token!

The android.media.session.MediaSession.Token.

completionLooper: Looper!

The Looper on which the returned ListenableFuture completes. This Looper can't be used to call future.get() on the returned ListenableFuture.

equals

fun equals(obj: Any?): Boolean

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 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>

getExtras

fun getExtras(): Bundle!

Returns the extra Bundle of this token.

See also
setExtras

getInterfaceVersion

@UnstableApi
fun getInterfaceVersion(): Int

Returns the interface version of the session if the type is TYPE_SESSION. Otherwise, it returns 0.

getPackageName

fun getPackageName(): String!

Returns the package name of the session

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 if the type is TYPE_SESSION. Otherwise, it returns 0.

It will be the same as VERSION_INT of the session, or less than 1000000 if the session is a legacy 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.

hashCode

fun hashCode(): Int

toBundle

@UnstableApi
fun toBundle(): Bundle!

Returns a Bundle representing the information stored in this object.

toString

fun toString(): String!