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

Unit

Terminates the session and closes Chooser.

Rect?

Gets the last bounds reported by the Chooser.

Int

ChooserSessionToken

Returns this session's token.

Unit

Removes a previously added UpdateListener callback.

Unit

Sets whether the targets in the chooser UI are enabled.

Unit

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: 2

STATE_INITIALIZED

static val STATE_INITIALIZED: Int

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

Value: 0

STATE_STARTED

static val STATE_STARTED: Int

The chooser is connected and can be updated.

Value: 1

Public methods

addStateListener

fun addStateListener(
    executor: Executor,
    listener: ChooserSession.StateListener
): Unit
Parameters
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.
executor Executor: 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).

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:

This method is a no-op if the session is not in the STATE_STARTED state.
Parameters
intent Intent: The new intent to apply to the session. This value cannot be null.