# Session2Token

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Session2Token

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/android/media/Session2Token "View this page in Java")  

```
class Session2Token : Parcelable
```

|---|------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                             ||
| ↳ | [android.media.Session2Token](https://developer.android.com/reference/kotlin/android/media/Session2Token#) |

This API is not generally intended for third party application developers. Use the[AndroidX](https://developer.android.com/jetpack/androidx.html)[Media3 session Library](https://developer.android.com/media/media3/session/control-playback)for consistent behavior across all devices.

Represents an ongoing[MediaSession2](https://developer.android.com/reference/kotlin/android/media/MediaSession2)or a[MediaSession2Service](https://developer.android.com/reference/kotlin/android/media/MediaSession2Service). If it's representing a session service, it may not be ongoing.

This may be passed to apps by the session owner to allow them to create a[MediaController2](https://developer.android.com/reference/kotlin/android/media/MediaController2)to communicate with the session.

It can be also obtained by[android.media.session.MediaSessionManager](https://developer.android.com/reference/kotlin/android/media/session/MediaSessionManager).

## Summary

|                                                                                                                                                                Constants                                                                                                                                                                ||
|----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [TYPE_SESSION](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION:kotlin.Int) Type for[MediaSession2](https://developer.android.com/reference/kotlin/android/media/MediaSession2).                               |
| static[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [TYPE_SESSION_SERVICE](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION_SERVICE:kotlin.Int) Type for[MediaSession2Service](https://developer.android.com/reference/kotlin/android/media/MediaSession2Service). |

| Inherited constants ||
|---|---|
| From class[Parcelable](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#) |----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#CONTENTS_FILE_DESCRIPTOR:kotlin.Int) <br /> Descriptor bit used with[describeContents()](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#describeContents()): indicates that the Parcelable object's flattened representation includes a file descriptor. <br />                                                                                                                                                                                                        | | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | [PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int) <br /> Flag for use with[writeToParcel](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#writeToParcel(android.os.Parcel,%20kotlin.Int)): the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`". Some implementations may want to release resources at this point. <br /> | ||

|                                                                                                                                                                                                                                                                               Public constructors                                                                                                                                                                                                                                                                                ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [Session2Token](https://developer.android.com/reference/kotlin/android/media/Session2Token#Session2Token(android.content.Context,%20android.content.ComponentName))`(`context:` `[Context](https://developer.android.com/reference/kotlin/android/content/Context.html#)`, `serviceComponent:` `[ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#)`)` Constructor for the token with type[TYPE_SESSION_SERVICE](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION_SERVICE:kotlin.Int). |

|                                                                                                                                                                                                       Public methods                                                                                                                                                                                                       ||
|------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [describeContents](https://developer.android.com/reference/kotlin/android/media/Session2Token#describeContents())`()` <br />                                                                                                                                                                                                           |
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | [equals](https://developer.android.com/reference/kotlin/android/media/Session2Token#equals(kotlin.Any))`(`other:` `[Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)?`)` <br />                                                                                                                               |
| [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#)   | [getExtras](https://developer.android.com/reference/kotlin/android/media/Session2Token#getExtras())`()` <br />                                                                                                                                                                                                                         |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)   | [getPackageName](https://developer.android.com/reference/kotlin/android/media/Session2Token#getPackageName())`()` <br />                                                                                                                                                                                                               |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)?  | [getServiceName](https://developer.android.com/reference/kotlin/android/media/Session2Token#getServiceName())`()` <br />                                                                                                                                                                                                               |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getType](https://developer.android.com/reference/kotlin/android/media/Session2Token#getType())`()` <br />                                                                                                                                                                                                                             |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [getUid](https://developer.android.com/reference/kotlin/android/media/Session2Token#getUid())`()` <br />                                                                                                                                                                                                                               |
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)         | [hashCode](https://developer.android.com/reference/kotlin/android/media/Session2Token#hashCode())`()` <br />                                                                                                                                                                                                                           |
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)   | [toString](https://developer.android.com/reference/kotlin/android/media/Session2Token#toString())`()` <br />                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html)       | [writeToParcel](https://developer.android.com/reference/kotlin/android/media/Session2Token#writeToParcel(android.os.Parcel,%20kotlin.Int))`(`dest:` `[Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#)`, `flags:` `[Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)`)` <br /> |

|                                                                                                                                                                     Properties                                                                                                                                                                      ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| static[Parcelable.Creator](https://developer.android.com/reference/kotlin/android/os/Parcelable.Creator.html#)\<[Session2Token](https://developer.android.com/reference/kotlin/android/media/Session2Token#)!\> | [CREATOR](https://developer.android.com/reference/kotlin/android/media/Session2Token#CREATOR:android.os.Parcelable.Creator) <br /> |

## Constants

### TYPE_SESSION

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val TYPE_SESSION: Int
```

Type for[MediaSession2](https://developer.android.com/reference/kotlin/android/media/MediaSession2).  

    Value: 0

### TYPE_SESSION_SERVICE

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val TYPE_SESSION_SERVICE: Int
```

Type for[MediaSession2Service](https://developer.android.com/reference/kotlin/android/media/MediaSession2Service).  

    Value: 1

## Public constructors

### Session2Token

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
Session2Token(
    context: Context, 
    serviceComponent: ComponentName)
```

Constructor for the token with type[TYPE_SESSION_SERVICE](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION_SERVICE:kotlin.Int).

|                                                                                       Parameters                                                                                       ||
|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `context`          | [Context](https://developer.android.com/reference/kotlin/android/content/Context.html#):The context. This value cannot be`null`.                                   |
| `serviceComponent` | [ComponentName](https://developer.android.com/reference/kotlin/android/content/ComponentName.html#):The component name of the service. This value cannot be`null`. |

## Public methods

### describeContents

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun describeContents(): Int
```

|                                                                                                                                                                               Return                                                                                                                                                                               ||
|----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either`0`or[android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#CONTENTS_FILE_DESCRIPTOR:kotlin.Int) |

### equals

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun equals(other: Any?): Boolean
```

|                     Parameters                     ||
|-------|---------------------------------------------|
| `obj` | the reference object with which to compare. |

|                                                                           Return                                                                           ||
|------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `true`if this object is the same as the obj argument;`false`otherwise. |

### getExtras

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getExtras(): Bundle
```

|                                                              Return                                                               ||
|----------------------------------------------------------------------------------|-------------------------------------------------|
| [Bundle](https://developer.android.com/reference/kotlin/android/os/Bundle.html#) | extras of the token This value cannot be`null`. |

**See Also**

- [android.media.MediaSession2.Builder#setExtras(Bundle)](https://developer.android.com/reference/kotlin/android/media/MediaSession2.Builder#setExtras(android.os.Bundle))  

### getPackageName

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getPackageName(): String
```

|                                                                  Return                                                                   ||
|----------------------------------------------------------------------------------|---------------------------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | package name of the session This value cannot be`null`. |

### getServiceName

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getServiceName(): String?
```

|                                                                                                                       Return                                                                                                                       ||
|-----------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)? | service name of the session. Can be`null`for[TYPE_SESSION](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION:kotlin.Int). |

### getType

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getType(): Int
```

|                                                                                                                                                                                                         Return                                                                                                                                                                                                         ||
|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | type of the token Value is[android.media.Session2Token#TYPE_SESSION](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION:kotlin.Int), or[android.media.Session2Token#TYPE_SESSION_SERVICE](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION_SERVICE:kotlin.Int) |

**See Also**

- [#TYPE_SESSION](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION:kotlin.Int)
- [#TYPE_SESSION_SERVICE](https://developer.android.com/reference/kotlin/android/media/Session2Token#TYPE_SESSION_SERVICE:kotlin.Int)  

### getUid

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun getUid(): Int
```

|                                             Return                                             ||
|----------------------------------------------------------------------------|--------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | uid of the session |

### hashCode

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun hashCode(): Int
```

|                                                     Return                                                     ||
|----------------------------------------------------------------------------|------------------------------------|
| [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | a hash code value for this object. |

### toString

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun toString(): String
```

|                                                          Return                                                          ||
|----------------------------------------------------------------------------------|----------------------------------------|
| [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | a string representation of the object. |

### writeToParcel

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
fun writeToParcel(
    dest: Parcel, 
    flags: Int
): Unit
```

|                                                                                                                                                                                                                                                                                     Parameters                                                                                                                                                                                                                                                                                     ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `dest`  | [Parcel](https://developer.android.com/reference/kotlin/android/os/Parcel.html#):The Parcel in which the object should be written. This value cannot be`null`.                                                                                                                                                                                                                                                                                                                                                                                                            |
| `flags` | [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html):Additional flags about how the object should be written. May be 0 or[PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int). Value is either`0`or a combination of[android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE](https://developer.android.com/reference/kotlin/android/os/Parcelable.html#PARCELABLE_WRITE_RETURN_VALUE:kotlin.Int), and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |

## Properties

### CREATOR

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
static val CREATOR: Parcelable.Creator<Session2Token!>
```