PlaybackPendingIntentBuilder


@UnstableApi
class PlaybackPendingIntentBuilder


A builder for creating a PendingIntent for a given Player.Command to be sent 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

PlaybackPendingIntentBuilder(
    context: Context!,
    @Player.Command command: Int,
    serviceClass: Class<MediaSessionService!>!
)

Creates a builder for a PendingIntent for a given Player.Command.

Public functions

PendingIntent!

Builds the PendingIntent.

java-static Intent!
createMediaButtonIntent(
    context: Context!,
    @Player.Command command: Int,
    extras: Bundle?,
    sessionId: String?,
    serviceClass: Class<MediaSessionService!>!
)

Creates an Intent for a media button event.

java-static Boolean

Returns whether the given Player.Command is supported.

PlaybackPendingIntentBuilder!

Sets the additional extras of the Intent.

PlaybackPendingIntentBuilder!

Sets the ID of the session.

PlaybackPendingIntentBuilder!

Sets whether the service should be started into the foreground.

Public constructors

PlaybackPendingIntentBuilder

PlaybackPendingIntentBuilder(
    context: Context!,
    @Player.Command command: Int,
    serviceClass: Class<MediaSessionService!>!
)

Creates a builder for a PendingIntent for a given Player.Command.

Throws an IllegalArgumentException if the Player.Command is not in the set of supported commands. Supported commands are:

Parameters
context: Context!

The context.

@Player.Command command: Int

The Player.Command.

serviceClass: Class<MediaSessionService!>!

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

Public functions

build

fun build(): PendingIntent!

Builds the PendingIntent.

Two PendingIntent instances for the same command are considered the same. The key code of the command is used as the request code.

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

createMediaButtonIntent

java-static fun createMediaButtonIntent(
    context: Context!,
    @Player.Command command: Int,
    extras: Bundle?,
    sessionId: String?,
    serviceClass: Class<MediaSessionService!>!
): Intent!

Creates an Intent for a media button event.

Throws an IllegalArgumentException if the Player.Command is not in the set of supported commands. Supported commands are:

Parameters
context: Context!

The context.

@Player.Command command: Int

The Player.Command.

extras: Bundle?

The additional extras.

sessionId: String?

The ID of the session or null if the default session ID should be used.

serviceClass: Class<MediaSessionService!>!

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

Returns
Intent!

The created Intent.

isCommandSupported

java-static fun isCommandSupported(@Player.Command command: Int): Boolean

Returns whether the given Player.Command is supported.

Parameters
@Player.Command command: Int

The Player.Command.

Returns
Boolean

Whether the given Player.Command is supported.

setExtras

@CanIgnoreReturnValue
fun setExtras(extras: Bundle!): PlaybackPendingIntentBuilder!

Sets the additional extras of the Intent.

Parameters
extras: Bundle!

The additional extras.

Returns
PlaybackPendingIntentBuilder!

This builder.

setSessionId

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

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

This builder.

setStartAsForegroundService

@CanIgnoreReturnValue
fun setStartAsForegroundService(startAsForegroundService: Boolean): PlaybackPendingIntentBuilder!

Sets whether the service should be started into the foreground.

This is usually the case for the COMMAND_PLAY_PAUSE command only, hence when getPlayWhenReady is false. The default value is false.

Parameters
startAsForegroundService: Boolean

Whether the service should be started into the foreground.

Returns
PlaybackPendingIntentBuilder!

This builder.