ChooserSession
class ChooserSession
| kotlin.Any | |
| ↳ | android.service.chooser.ChooserSession |
A class that represents an interactive Chooser session.
A StateListener callback can be used to receive updates about the session and communication from Chooser.
Summary
| Nested classes | |
|---|---|
| abstract |
A callback interface for Chooser session state updates. |
| Constants | |
|---|---|
| static Int |
The session is closed by either side. |
| static Int |
The initial state: the session is initialized but the Chooser has not yet connected. |
| static Int |
The chooser is connected and can be updated. |
| Public methods | |
|---|---|
| Unit |
addStateListener(executor: Executor, listener: ChooserSession.StateListener) |
| Unit |
Terminates the session and closes Chooser. |
| Rect? |
Gets the last bounds reported by the Chooser. |
| Rect? |
Returns the initial resting bound for the Chooser, or |
| Int |
getState() |
| ChooserSessionToken |
getToken()Returns this session's token. |
| Unit |
removeStateListener(listener: ChooserSession.StateListener)Removes a previously added UpdateListener callback. |
| Unit |
setTargetsEnabled(isEnabled: Boolean)Sets whether the targets in the chooser UI are enabled. |
| Unit |
updateIntent(intent: Intent)Updates the chooser intent in an active Chooser session, causing Chooser to refresh its state and targets. |
Constants
STATE_CLOSED
static val STATE_CLOSED: Int
The session is closed by either side.
Value: 2STATE_INITIALIZED
static val STATE_INITIALIZED: Int
The initial state: the session is initialized but the Chooser has not yet connected.
Value: 0STATE_STARTED
static val STATE_STARTED: Int
The chooser is connected and can be updated.
Value: 1Public methods
addStateListener
fun addStateListener(
executor: Executor,
listener: ChooserSession.StateListener
): Unit
| Parameters | |
|---|---|
executor |
Executor: This value cannot be null. |
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. |
endSession
fun endSession(): Unit
Terminates the session and closes Chooser.
getBounds
fun getBounds(): Rect?
Gets the last bounds reported by the Chooser.
| Return | |
|---|---|
Rect? |
the most recently reported Chooser bounds, or null if bounds have not yet been received via ChooserSession.StateListener.onBoundsChanged(Rect). |
getInitialRestingBounds
fun getInitialRestingBounds(): Rect?
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 ChooserSession.StateListener.onBoundsChanged(Rect) invocation.
getState
fun getState(): Int
| Return | |
|---|---|
Int |
current session state. Value is one of the following: |
getToken
fun getToken(): ChooserSessionToken
Returns this session's token. A token serves as a session identifier and can be used to retrieve an active session from the ChooserManager.
| Return | |
|---|---|
ChooserSessionToken |
This value cannot be null. |
removeStateListener
fun removeStateListener(listener: ChooserSession.StateListener): Unit
Removes a previously added UpdateListener callback.
| Parameters | |
|---|---|
listener |
ChooserSession.StateListener: This value cannot be null. |
setTargetsEnabled
fun setTargetsEnabled(isEnabled: Boolean): Unit
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 STATE_STARTED.
updateIntent
fun updateIntent(intent: Intent): Unit
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:
Intent.EXTRA_INTENTIntent.EXTRA_EXCLUDE_COMPONENTSIntent.EXTRA_CHOOSER_TARGETSIntent.EXTRA_ALTERNATE_INTENTSIntent.EXTRA_REPLACEMENT_EXTRASIntent.EXTRA_INITIAL_INTENTSIntent.EXTRA_CHOOSER_RESULT_INTENT_SENDERIntent.EXTRA_CHOOSER_REFINEMENT_INTENT_SENDER
STATE_STARTED state.
| Parameters | |
|---|---|
intent |
Intent: The new intent to apply to the session. This value cannot be null. |