ChooserSession


public final class ChooserSession
extends Object

java.lang.Object
   ↳ 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.

See also:

Summary

Nested classes

interface ChooserSession.StateListener

A callback interface for Chooser session state updates. 

Constants

int STATE_CLOSED

The session is closed by either side.

int STATE_INITIALIZED

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

int STATE_STARTED

The chooser is connected and can be updated.

Public methods

void addStateListener(Executor executor, ChooserSession.StateListener listener)
void endSession()

Terminates the session and closes Chooser.

Rect getBounds()

Gets the last bounds reported by the Chooser.

int getState()
ChooserSessionToken getToken()

Returns this session's token.

void removeStateListener(ChooserSession.StateListener listener)

Removes a previously added UpdateListener callback.

void setTargetsEnabled(boolean isEnabled)

Sets whether the targets in the chooser UI are enabled.

void updateIntent(Intent intent)

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

Inherited methods

Constants

STATE_CLOSED

public static final int STATE_CLOSED

The session is closed by either side.

Constant Value: 2 (0x00000002)

STATE_INITIALIZED

public static final int STATE_INITIALIZED

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

Constant Value: 0 (0x00000000)

STATE_STARTED

public static final int STATE_STARTED

The chooser is connected and can be updated.

Constant Value: 1 (0x00000001)

Public methods

addStateListener

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

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

public void endSession ()

Terminates the session and closes Chooser.

getBounds

public Rect getBounds ()

Gets the last bounds reported by the Chooser.

Returns
Rect the most recently reported Chooser bounds, or null if bounds have not yet been received via ChooserSession.StateListener.onBoundsChanged(Rect).

getState

public int getState ()

Returns
int current session state. Value is STATE_INITIALIZED, STATE_STARTED, or STATE_CLOSED

getToken

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 ChooserManager.

Returns
ChooserSessionToken This value cannot be null.

removeStateListener

public void removeStateListener (ChooserSession.StateListener listener)

Removes a previously added UpdateListener callback.

Parameters
listener ChooserSession.StateListener: This value cannot be null.

setTargetsEnabled

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 STATE_STARTED.

Parameters
isEnabled boolean

updateIntent

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:

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.