# 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
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/kotlin/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/kotlin/androidx/media3/session/MediaController` or `https://developer.android.com/reference/kotlin/androidx/media3/session/MediaBrowser` instead of a `https://developer.android.com/reference/android/app/PendingIntent.html`.

## Summary

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

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

## Public constructors

### CustomCommandPendingIntentBuilder

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

Creates an instance.

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

## Public functions

### build

```
fun build(): PendingIntent!
```

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

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

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

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | The context. |
| `customSessionCommand: https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand!` | The custom `https://developer.android.com/reference/kotlin/androidx/media3/session/SessionCommand`. |
| `sessionId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The ID of the session as set with `https://developer.android.com/reference/kotlin/androidx/media3/session/MediaSession.Builder#setId(java.lang.String)` or null if the default ID was used when building the session. |
| `serviceClass: https://developer.android.com/reference/java/lang/Class.html<https://developer.android.com/reference/kotlin/androidx/media3/session/MediaSessionService!>!` | 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
fun setSessionId(sessionId: String?): CustomCommandPendingIntentBuilder!
```

Sets the ID of the session.

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

| Parameters |
|---|---|
| `sessionId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The ID of the session as set with `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/session/CustomCommandPendingIntentBuilder!` | This builder. |