ChooserManager
open class ChooserManager
kotlin.Any | |
↳ | 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:
<code>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 } </code>
Summary
Public methods | |
---|---|
open ChooserSession? |
getSession(token: ChooserSessionToken) Returns a |
open ChooserSession |
startSession(context: Context, chooserIntent: Intent) Starts a new interactive Chooser session. |
Public methods
getSession
open fun getSession(token: ChooserSessionToken): ChooserSession?
Returns a ChooserSession
associated with this token or null
if there is no active session.
Parameters | |
---|---|
token |
ChooserSessionToken: ChooserSessionToken . This value cannot be null . |
startSession
open fun startSession(
context: Context,
chooserIntent: Intent
): ChooserSession
Starts a new interactive Chooser session. The method is idempotent and will start Chooser only once.
Parameters | |
---|---|
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 null . |
context |
Context: This value cannot be null . |
Return | |
---|---|
ChooserSession |
This value cannot be null . |