# SessionCommand

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/SessionCommand.java+class:androidx.media3.session.SessionCommand)

*** ** * ** ***


```
public final class SessionCommand
```

<br />

*** ** * ** ***

A command that a `https://developer.android.com/reference/androidx/media3/session/MediaController` can send to a `https://developer.android.com/reference/androidx/media3/session/MediaSession`.

If `https://developer.android.com/reference/androidx/media3/session/SessionCommand#commandCode()` isn't `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM()`, it's a predefined command. If `https://developer.android.com/reference/androidx/media3/session/SessionCommand#commandCode()` is `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM()`, it's a custom command and `https://developer.android.com/reference/androidx/media3/session/SessionCommand#customAction()` must not be `null`.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) @https://developer.android.com/reference/androidx/annotation/IntDef(value = ) public annotation https://developer.android.com/reference/androidx/media3/session/SessionCommand.CommandCode` Command codes of session commands. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM() = 0` Command code for the custom command which can be defined by string action in the `https://developer.android.com/reference/androidx/media3/session/SessionCommand`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_CHILDREN() = 50003` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getChildren(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_ITEM() = 50004` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getItem(java.lang.String)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT() = 50000` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getLibraryRoot(androidx.media3.session.MediaLibraryService.LibraryParams)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT() = 50006` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getSearchResult(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_SEARCH() = 50005` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#search(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_SUBSCRIBE() = 50001` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#subscribe(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_LIBRARY_UNSUBSCRIBE() = 50002` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#unsubscribe(java.lang.String)`. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_SESSION_SET_RATING() = 40010` Command code for `https://developer.android.com/reference/androidx/media3/session/MediaController#setRating(java.lang.String,androidx.media3.common.Rating)`. |

| ### Public fields |
|---|---|
| `final int` | `@https://developer.android.com/reference/androidx/media3/session/SessionCommand.CommandCode https://developer.android.com/reference/androidx/media3/session/SessionCommand#commandCode()` The command code of a predefined command. |
| `final https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#customAction()` The action of a custom command. |
| `final https://developer.android.com/reference/android/os/Bundle.html` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#customExtras()` The extra bundle of a custom command. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/session/SessionCommand#SessionCommand(int)(@https://developer.android.com/reference/androidx/media3/session/SessionCommand.CommandCode int commandCode)` Creates a predefined command. |
| `https://developer.android.com/reference/androidx/media3/session/SessionCommand#SessionCommand(java.lang.String,android.os.Bundle)(https://developer.android.com/reference/java/lang/String.html action, https://developer.android.com/reference/android/os/Bundle.html extras)` Creates a custom command. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html obj)` Checks the given session command for equality while ignoring extras. |
| `static https://developer.android.com/reference/androidx/media3/session/SessionCommand` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/session/SessionCommand#fromBundle(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html bundle)` Restores a `SessionCommand` from a `https://developer.android.com/reference/android/os/Bundle.html`. |
| `int` | `https://developer.android.com/reference/androidx/media3/session/SessionCommand#hashCode()()` |
| `https://developer.android.com/reference/android/os/Bundle.html` | `@https://developer.android.com/reference/androidx/media3/common/util/UnstableApi https://developer.android.com/reference/androidx/media3/session/SessionCommand#toBundle()()` |

## Constants

### COMMAND_CODE_CUSTOM

```
public static final int COMMAND_CODE_CUSTOM = 0
```

Command code for the custom command which can be defined by string action in the `https://developer.android.com/reference/androidx/media3/session/SessionCommand`.

### COMMAND_CODE_LIBRARY_GET_CHILDREN

```
public static final int COMMAND_CODE_LIBRARY_GET_CHILDREN = 50003
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getChildren(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)`.

### COMMAND_CODE_LIBRARY_GET_ITEM

```
public static final int COMMAND_CODE_LIBRARY_GET_ITEM = 50004
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getItem(java.lang.String)`.

### COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT

```
public static final int COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT = 50000
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getLibraryRoot(androidx.media3.session.MediaLibraryService.LibraryParams)`.

### COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT

```
public static final int COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT = 50006
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#getSearchResult(java.lang.String,int,int,androidx.media3.session.MediaLibraryService.LibraryParams)`.

### COMMAND_CODE_LIBRARY_SEARCH

```
public static final int COMMAND_CODE_LIBRARY_SEARCH = 50005
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#search(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)`.

### COMMAND_CODE_LIBRARY_SUBSCRIBE

```
public static final int COMMAND_CODE_LIBRARY_SUBSCRIBE = 50001
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#subscribe(java.lang.String,androidx.media3.session.MediaLibraryService.LibraryParams)`.

### COMMAND_CODE_LIBRARY_UNSUBSCRIBE

```
public static final int COMMAND_CODE_LIBRARY_UNSUBSCRIBE = 50002
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaBrowser#unsubscribe(java.lang.String)`.

### COMMAND_CODE_SESSION_SET_RATING

```
public static final int COMMAND_CODE_SESSION_SET_RATING = 40010
```

Command code for `https://developer.android.com/reference/androidx/media3/session/MediaController#setRating(java.lang.String,androidx.media3.common.Rating)`.

## Public fields

### commandCode

```
@SessionCommand.CommandCode
public final int commandCode
```

The command code of a predefined command. It will be `https://developer.android.com/reference/androidx/media3/session/SessionCommand#COMMAND_CODE_CUSTOM()` for a custom command.

### customAction

```
public final String customAction
```

The action of a custom command. It will be an empty string for a predefined command.

### customExtras

```
public final Bundle customExtras
```

The extra bundle of a custom command. It will be `https://developer.android.com/reference/android/os/Bundle.html#EMPTY` for a predefined command.

## Public constructors

### SessionCommand

```
public SessionCommand(@SessionCommand.CommandCode int commandCode)
```

Creates a predefined command.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/media3/session/SessionCommand.CommandCode int commandCode` | A command code for a predefined command. |

### SessionCommand

```
public SessionCommand(String action, Bundle extras)
```

Creates a custom command.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html action` | The action of this custom command. |
| `https://developer.android.com/reference/android/os/Bundle.html extras` | An extra bundle for this custom command. This value is not used when the command is sent to a legacy `android.support.v4.media.session.MediaSessionCompat` or ` android.support.v4.media.session.MediaControllerCompat`. |

## Public methods

### equals

```
public boolean equals(@Nullable Object obj)
```

Checks the given session command for equality while ignoring extras.

### fromBundle

```
@UnstableApi
public static SessionCommand fromBundle(Bundle bundle)
```

Restores a `SessionCommand` from a `https://developer.android.com/reference/android/os/Bundle.html`.

### hashCode

```
public int hashCode()
```

### toBundle

```
@UnstableApi
public Bundle toBundle()
```