SessionToken
public final class SessionToken
A token that represents an ongoing MediaSession
or a service (, 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 or a MediaBrowser
to communicate with the session.
It can also be obtained by getAllServiceTokens
.
Summary
Nested types |
---|
@Documented Types of |
Constants |
|
---|---|
static final int |
Type for |
static final int |
TYPE_SESSION = 0 Type for |
static final int |
Type for |
Public constructors |
---|
SessionToken(Context context, ComponentName serviceComponent) Creates a token for |
Public methods |
|
---|---|
static ListenableFuture<SessionToken> |
createSessionToken(Context context, MediaSession.Token token) Creates a token from a platform |
static ListenableFuture<SessionToken> |
@UnstableApi Creates a token from a platform |
static ListenableFuture<SessionToken> |
@UnstableApi Creates a token from a platform |
static ListenableFuture<SessionToken> |
@UnstableApi Creates a token from a platform |
boolean |
|
static SessionToken |
@UnstableApi Restores a |
static ImmutableSet<SessionToken> |
getAllServiceTokens(Context context) Returns an |
Bundle |
Returns the extra |
int |
Returns the interface version of the session if the |
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 |
int |
Returns the type of this token. |
int |
getUid() Returns the UID of the session process, or |
int |
hashCode() |
Bundle |
|
String |
toString() |
Constants
Public constructors
SessionToken
public SessionToken(Context context, ComponentName serviceComponent)
Creates a token for MediaController
or MediaBrowser
to connect to one of , MediaLibraryService
, or
androidx.media.MediaBrowserServiceCompat
.
Parameters | |
---|---|
Context context |
The context. |
ComponentName serviceComponent |
The component name of the service. |
Public methods
createSessionToken
public static ListenableFuture<SessionToken> createSessionToken(Context context, MediaSession.Token token)
Creates a token from a platform Token
.
Parameters | |
---|---|
Context context |
A |
MediaSession.Token token |
The platform |
Returns | |
---|---|
ListenableFuture<SessionToken> |
A |
createSessionToken
@UnstableApi
public static ListenableFuture<SessionToken> createSessionToken(Context context, Parcelable token)
Creates a token from a platform Token
or
android.support.v4.media.session.MediaSessionCompat.Token
.
Parameters | |
---|---|
Context context |
A |
Parcelable token |
The |
Returns | |
---|---|
ListenableFuture<SessionToken> |
A |
createSessionToken
@UnstableApi
public static ListenableFuture<SessionToken> createSessionToken(
Context context,
MediaSession.Token token,
Looper completionLooper
)
Creates a token from a platform Token
.
Parameters | |
---|---|
Context context |
A |
MediaSession.Token token |
The platform |
Looper completionLooper |
The |
Returns | |
---|---|
ListenableFuture<SessionToken> |
A |
createSessionToken
@UnstableApi
public static ListenableFuture<SessionToken> createSessionToken(
Context context,
Parcelable token,
Looper completionLooper
)
Creates a token from a platform Token
or
android.support.v4.media.session.MediaSessionCompat.Token
.
Parameters | |
---|---|
Context context |
A |
Parcelable token |
The |
Looper completionLooper |
The |
Returns | |
---|---|
ListenableFuture<SessionToken> |
A |
fromBundle
@UnstableApi
public static SessionToken fromBundle(Bundle bundle)
Restores a SessionToken
from a Bundle
.
getAllServiceTokens
public static ImmutableSet<SessionToken> getAllServiceTokens(Context context)
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>
getInterfaceVersion
@UnstableApi
public int getInterfaceVersion()
Returns the interface version of the session if the type
is TYPE_SESSION
. Otherwise, it returns 0
.
getServiceName
public String getServiceName()
Returns the service name of the session. It will be an empty string if the type
is TYPE_SESSION
.
getSessionVersion
public int getSessionVersion()
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
public int getType()
Returns the type of this token. One of TYPE_SESSION
, TYPE_SESSION_SERVICE
, or TYPE_LIBRARY_SERVICE
.
getUid
public int getUid()
Returns the UID of the session process, or INDEX_UNSET
if the UID can't be determined due to missing package visibility.