# CustomCommandPendingIntentBuilder

Artifact: [androidx.media3:media3-session](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/session/CustomCommandPendingIntentBuilder.java+class:androidx.media3.session.CustomCommandPendingIntentBuilder)

*** ** * ** ***


```
@UnstableApi
public final class CustomCommandPendingIntentBuilder
```

<br />

*** ** * ** ***

Builds a `https://developer.android.com/reference/android/app/PendingIntent.html` to send a custom command to a `https://developer.android.com/reference/androidx/media3/session/MediaSessionService`.

This builder is primarily intended for creating `https://developer.android.com/reference/android/app/PendingIntent.html` instances used in home screen widgets (see [App widgets overview](https://developer.android.com/develop/ui/views/appwidgets/overview)). For other use cases, such as interacting with a Media3 session service from within an app, it is strongly recommended to use a `https://developer.android.com/reference/androidx/media3/session/MediaController` or `https://developer.android.com/reference/androidx/media3/session/MediaBrowser` instead of a `https://developer.android.com/reference/android/app/PendingIntent.html`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/session/CustomCommandPendingIntentBuilder#CustomCommandPendingIntentBuilder(android.content.Context,java.lang.Class<? extends androidx.media3.session.MediaSessionService>,androidx.media3.session.SessionCommand)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/androidx/media3/session/MediaSessionService> serviceClass, https://developer.android.com/reference/androidx/media3/session/SessionCommand customSessionCommand )` Creates an instance. |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/androidx/media3/session/CustomCommandPendingIntentBuilder#build()()` Builds the `https://developer.android.com/reference/android/app/PendingIntent.html`. |
| `static https://developer.android.com/reference/android/content/Intent.html` | `https://developer.android.com/reference/androidx/media3/session/CustomCommandPendingIntentBuilder#createCustomCommandIntent(android.content.Context,androidx.media3.session.SessionCommand,java.lang.String,java.lang.Class<? extends androidx.media3.session.MediaSessionService>)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/androidx/media3/session/SessionCommand customSessionCommand, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html sessionId, https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/androidx/media3/session/MediaSessionService> serviceClass )` Creates an `https://developer.android.com/reference/android/content/Intent.html` to send a custom command to a `https://developer.android.com/reference/androidx/media3/session/MediaSessionService`. |
| `https://developer.android.com/reference/androidx/media3/session/CustomCommandPendingIntentBuilder` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/androidx/media3/session/CustomCommandPendingIntentBuilder#setSessionId(java.lang.String)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html sessionId)` Sets the ID of the session. |

## Public constructors

### CustomCommandPendingIntentBuilder

```
public CustomCommandPendingIntentBuilder(
    Context context,
    Class<MediaSessionService> serviceClass,
    SessionCommand customSessionCommand
)
```

Creates an instance.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The context. |
| `https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/androidx/media3/session/MediaSessionService> serviceClass` | The class of the service to which the intent should be sent. |
| `https://developer.android.com/reference/androidx/media3/session/SessionCommand customSessionCommand` | The custom `https://developer.android.com/reference/androidx/media3/session/SessionCommand`. |

## Public methods

### build

```
public PendingIntent build()
```

Builds the `https://developer.android.com/reference/android/app/PendingIntent.html`.

Each `https://developer.android.com/reference/android/app/PendingIntent.html` has a random request code. Any created `https://developer.android.com/reference/android/app/PendingIntent.html` can be `https://developer.android.com/reference/android/content/Intent.html#filterEquals(android.content.Intent)`.

The `https://developer.android.com/reference/android/app/PendingIntent.html` is created with the flags `PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_IMMUTABLE`.

### createCustomCommandIntent

```
public static Intent createCustomCommandIntent(
    Context context,
    SessionCommand customSessionCommand,
    @Nullable String sessionId,
    Class<MediaSessionService> serviceClass
)
```

Creates an `https://developer.android.com/reference/android/content/Intent.html` to send a custom command to a `https://developer.android.com/reference/androidx/media3/session/MediaSessionService`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/content/Context.html context` | The context. |
| `https://developer.android.com/reference/androidx/media3/session/SessionCommand customSessionCommand` | The custom `https://developer.android.com/reference/androidx/media3/session/SessionCommand`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html sessionId` | The ID of the session as set with `https://developer.android.com/reference/androidx/media3/session/MediaSession.Builder#setId(java.lang.String)` or null if the default ID was used when building the session. |
| `https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/androidx/media3/session/MediaSessionService> serviceClass` | The class of the service to which the intent should be sent. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/content/Intent.html` | The `https://developer.android.com/reference/android/content/Intent.html`. |

### setSessionId

```
@CanIgnoreReturnValue
public CustomCommandPendingIntentBuilder setSessionId(@Nullable String sessionId)
```

Sets the ID of the session.

The default value is `null`, which corresponds to the default ID used when `https://developer.android.com/reference/androidx/media3/session/MediaSession.Builder#setId(java.lang.String)` was not called when building the session.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html sessionId` | The ID of the session as set with `https://developer.android.com/reference/androidx/media3/session/MediaSession.Builder#setId(java.lang.String)` or null if the default ID was used when building the session. |

| Returns |
|---|---|
| `https://developer.android.com/reference/androidx/media3/session/CustomCommandPendingIntentBuilder` | This builder. |