CustomCommandPendingIntentBuilder


@UnstableApi
class CustomCommandPendingIntentBuilder


Builds a PendingIntent to send a custom command to a MediaSessionService.

This builder is primarily intended for creating PendingIntent instances used in home screen widgets (see App widgets overview). For other use cases, such as interacting with a Media3 session service from within an app, it is strongly recommended to use a MediaController or MediaBrowser instead of a PendingIntent.

Summary

Public constructors

CustomCommandPendingIntentBuilder(
    context: Context!,
    serviceClass: Class<MediaSessionService!>!,
    customSessionCommand: SessionCommand!
)

Creates an instance.

Public functions

PendingIntent!

Builds the PendingIntent.

java-static Intent!
createCustomCommandIntent(
    context: Context!,
    customSessionCommand: SessionCommand!,
    sessionId: String?,
    serviceClass: Class<MediaSessionService!>!
)

Creates an Intent to send a custom command to a MediaSessionService.

CustomCommandPendingIntentBuilder!

Sets the ID of the session.

Public constructors

CustomCommandPendingIntentBuilder

CustomCommandPendingIntentBuilder(
    context: Context!,
    serviceClass: Class<MediaSessionService!>!,
    customSessionCommand: SessionCommand!
)

Creates an instance.

Parameters
context: Context!

The context.

serviceClass: Class<MediaSessionService!>!

The class of the service to which the intent should be sent.

customSessionCommand: SessionCommand!

The custom SessionCommand.

Public functions

build

fun build(): PendingIntent!

Builds the PendingIntent.

Each PendingIntent has a random request code. Any created PendingIntent can be considered different from all other instance.

The PendingIntent is created with the flags PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE.

createCustomCommandIntent

java-static fun createCustomCommandIntent(
    context: Context!,
    customSessionCommand: SessionCommand!,
    sessionId: String?,
    serviceClass: Class<MediaSessionService!>!
): Intent!

Creates an Intent to send a custom command to a MediaSessionService.

Parameters
context: Context!

The context.

customSessionCommand: SessionCommand!

The custom SessionCommand.

sessionId: String?

The ID of the session as set with setId or null if the default ID was used when building the session.

serviceClass: Class<MediaSessionService!>!

The class of the service to which the intent should be sent.

Returns
Intent!

The Intent.

setSessionId

@CanIgnoreReturnValue
fun setSessionId(sessionId: String?): CustomCommandPendingIntentBuilder!

Sets the ID of the session.

The default value is null, which which corresponds to the default ID used when setId was not called when building the session.

Parameters
sessionId: String?

The ID of the session as set with setId or null if the default ID was used when building the session.

Returns
CustomCommandPendingIntentBuilder!

This builder.