ChooserManager


public class ChooserManager
extends Object

java.lang.Object
   ↳ android.service.chooser.ChooserManager


Manages the creation, tracking, and retrieval of chooser sessions.

An Interactive Chooser Session allows apps to invoke the system Chooser without entirely covering app UI. Users may interact with both the app and Chooser, while bidirectional communication between the two ensures a consistent state.

Usage Example:

ChooserManager chooserManager = context.getSystemService(ChooserManager.class);
 if (chooserManager == null) {
     // handle the case when the interactive chooser session functionality is not supported.
 }

 // Construct the sharing intent
 Intent targetIntent = new Intent(Intent.ACTION_SEND);
 targetIntent.setType("text/plain");
 targetIntent.putExtra(Intent.EXTRA_TEXT, "This is a message that will be shared.");

 Intent chooserIntent = Intent.createChooser(targetIntent, null);

 // Start a new chooser session
 ChooserSession session = chooserManager.startSession(context, chooserIntent);
 ChooserSessionToken token = session.getToken();
 // Optionally, store the token int an activity saved state to re-associate with the session later

 // Later, to retrieve a session using a token:
 ChooserSessionToken retrievedToken = ... // obtain the stored token
 ChooserSession existingSession = chooserManager.getSession(retrievedToken);
 if (existingSession != null) {
 // Interact with the existing session
 }
 

Summary

Public methods

ChooserSession getSession(ChooserSessionToken token)

Returns a ChooserSession associated with this token or null if there is no active session.

ChooserSession startSession(Context context, Intent chooserIntent)

Starts a new interactive Chooser session.

Inherited methods

Public methods

getSession

public ChooserSession getSession (ChooserSessionToken token)

Returns a ChooserSession associated with this token or null if there is no active session.

Parameters
token ChooserSessionToken: ChooserSessionToken. This value cannot be null.

Returns
ChooserSession

startSession

public ChooserSession startSession (Context context, 
                Intent chooserIntent)

Starts a new interactive Chooser session. The method is idempotent and will start Chooser only once.

Parameters
context Context: This value cannot be null.

chooserIntent Intent: an Intent.ACTION_CHOOSER intent that will be used as a base for the new Chooser session.

An interactive Chooser session also supports the following chooser parameters:

See also Intent.createChooser(Intent, CharSequence).

This value cannot be null.

Returns
ChooserSession This value cannot be null.