Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions) Summary: [Nested Classes](https://developer.android.com/reference/android/service/chooser/ChooserSession#nestedclasses) \| [Constants](https://developer.android.com/reference/android/service/chooser/ChooserSession#constants) \| [Methods](https://developer.android.com/reference/android/service/chooser/ChooserSession#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/service/chooser/ChooserSession#inhmethods)

# ChooserSession

*** ** * ** ***

` public final class ChooserSession `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.chooser.ChooserSession |

<br />

*** ** * ** ***

A class that represents an interactive Chooser session.

A `https://developer.android.com/reference/android/service/chooser/ChooserSession.StateListener` callback can be used to receive updates about the session and communication from Chooser.

<br />

**See also:**

- `https://developer.android.com/reference/android/service/chooser/ChooserManager`

## Summary

| ### Nested classes ||
|---|---|
| ` interface` | `https://developer.android.com/reference/android/service/chooser/ChooserSession.StateListener` A callback interface for Chooser session state updates. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_CLOSED` The session is closed by either side. |
| `int` | `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_INITIALIZED` The initial state: the session is initialized but the Chooser has not yet connected. |
| `int` | `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_STARTED` The chooser is connected and can be updated. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#addStateListener(java.util.concurrent.Executor,%20android.service.chooser.ChooserSession.StateListener)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/service/chooser/ChooserSession.StateListener listener) ` |
| ` void` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#endSession()() ` Terminates the session and closes Chooser. |
| ` https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#getBounds()() ` Gets the last bounds reported by the Chooser. |
| ` https://developer.android.com/reference/android/graphics/Rect` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#getInitialRestingBounds()() ` Returns the initial resting bound for the Chooser, or `null` if bounds have not yet been received. |
| ` int` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#getState()() ` |
| ` https://developer.android.com/reference/android/service/chooser/ChooserSessionToken` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#getToken()() ` Returns this session's token. |
| ` void` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#removeStateListener(android.service.chooser.ChooserSession.StateListener)(https://developer.android.com/reference/android/service/chooser/ChooserSession.StateListener listener) ` Removes a previously added UpdateListener callback. |
| ` void` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#setTargetsEnabled(boolean)(boolean isEnabled) ` Sets whether the targets in the chooser UI are enabled. |
| ` void` | ` https://developer.android.com/reference/android/service/chooser/ChooserSession#updateIntent(android.content.Intent)(https://developer.android.com/reference/android/content/Intent intent) ` Updates the chooser intent in an active Chooser session, causing Chooser to refresh its state and targets. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.

## Constants

### STATE_CLOSED

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int STATE_CLOSED
```

The session is closed by either side.

<br />

Constant Value: 2 (0x00000002)

### STATE_INITIALIZED

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int STATE_INITIALIZED
```

The initial state: the session is initialized but the Chooser has not yet connected.

<br />

Constant Value: 0 (0x00000000)

### STATE_STARTED

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final int STATE_STARTED
```

The chooser is connected and can be updated.

<br />

Constant Value: 1 (0x00000001)

## Public methods

### addStateListener

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void addStateListener (Executor executor, 
                ChooserSession.StateListener listener)
```

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: This value cannot be `null`. <br /> |
| `listener` | `ChooserSession.StateListener`: make sure that the callback is cleared at the end of a component's lifecycle (e.g. Activity) or provide a properly maintained WeakReference wrapper to avoid memory leaks. This value cannot be `null`. <br /> |

### endSession

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void endSession ()
```

Terminates the session and closes Chooser.

<br />

### getBounds

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public Rect getBounds ()
```

Gets the last bounds reported by the Chooser.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Rect` | the most recently reported Chooser bounds, or `null` if bounds have not yet been received via `https://developer.android.com/reference/android/service/chooser/ChooserSession.StateListener#onBoundsChanged(android.graphics.Rect)`. <br /> |

### getInitialRestingBounds

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

```
public Rect getInitialRestingBounds ()
```

Returns the initial resting bound for the Chooser, or `null` if bounds have not yet been received. This is the target position of the Chooser after any animation and data loading are complete.

This value is intended to help applications make an informed decision on how to react to Chooser bounds changes. For example, if the Chooser is a bottom sheet launched into a compact representation (but whose bounds can change later), this value can provide the dimensions for that initial compact representation. An application that wishes to limit its UI changes only to that specific size can use this value.

It is possible for this value to change (e.g., after a configuration change or after a target intent update) and the updated value should be available to the clients at the time of `https://developer.android.com/reference/android/service/chooser/ChooserSession.StateListener#onBoundsChanged(android.graphics.Rect)` invocation.

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Rect` | <br /> |

### getState

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public int getState ()
```

<br />

<br />

| Returns ||
|---|---|
| `int` | current session state. Value is one of the following: - `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_INITIALIZED` - `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_STARTED` - `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_CLOSED` |

**See also:**

- `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_INITIALIZED`
- `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_STARTED`
- `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_CLOSED`

### getToken

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public ChooserSessionToken getToken ()
```

Returns this session's token. A token serves as a session identifier and can be used to retrieve an active session from the `https://developer.android.com/reference/android/service/chooser/ChooserManager`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/service/chooser/ChooserSessionToken` | This value cannot be `null`. <br /> |

### removeStateListener

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void removeStateListener (ChooserSession.StateListener listener)
```

Removes a previously added UpdateListener callback.

<br />

| Parameters ||
|---|---|
| `listener` | `ChooserSession.StateListener`: This value cannot be `null`. <br /> |

### setTargetsEnabled

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void setTargetsEnabled (boolean isEnabled)
```

Sets whether the targets in the chooser UI are enabled. By default targets are enabled.

This method is primarily intended to allow for managing a transient state, particularly useful during long-running operations. By disabling targets, launching application can prevent unintended interactions.

A no-op when the session is not in the `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_STARTED`.

<br />

<br />

| Parameters ||
|---|---|
| `isEnabled` | `boolean` <br /> |

### updateIntent

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void updateIntent (Intent intent)
```

Updates the chooser intent in an active Chooser session, causing Chooser to refresh its state and targets.

Only updates to the following extras in the provided intent are respected:

- `https://developer.android.com/reference/android/content/Intent#EXTRA_INTENT`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_EXCLUDE_COMPONENTS`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_CHOOSER_TARGETS`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_ALTERNATE_INTENTS`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_REPLACEMENT_EXTRAS`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_INITIAL_INTENTS`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_CHOOSER_RESULT_INTENT_SENDER`
- `https://developer.android.com/reference/android/content/Intent#EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER`

This method is a no-op if the session is not in the `https://developer.android.com/reference/android/service/chooser/ChooserSession#STATE_STARTED` state.

<br />

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The new intent to apply to the session. This value cannot be `null`. <br /> |