AppInteractionSession
class AppInteractionSession : AutoCloseable
| kotlin.Any | |
| ↳ | android.app.AppInteractionSession |
Represents an app interaction session.
The session is used to associate app interactions with a continuous context. For example, a session can be used to keep track of the user consent for the lifetime of the session. Developers could use it to associate with relevant queries from users. For example, in a thread where a user starts asking an agent to perform a task, developers could start a session and keep track of all relevant actions within that session. So that if they need to access the same apps twice during that thread, they don't need to ask permission twice.
The session will be automatically closed when reaching the maximum allowed lifetime. The session owner will be notified of the close event via the AppInteractionSession.LifecycleListener.onAppInteractionSessionClosed with AppInteractionSession.CLOSE_REASON_TIMEOUT.
Summary
| Nested classes | |
|---|---|
|
Parameters to create an |
|
| abstract |
Listener for session lifecycle events. |
|
Parameters to update an |
|
| Constants | |
|---|---|
| static Int |
The session is closed due to the caller calling |
| static Int |
The session is closed due to timeout. |
| static Int |
Unknown reason for the session to be closed. |
| Public methods | |
|---|---|
| Unit |
addLifecycleListener(executor: Executor, listener: AppInteractionSession.LifecycleListener)Adds a listener to receive session lifecycle events. |
| Unit |
close()Closes the session. |
| Unit |
Removes a previously registered session lifecycle listener. |
| Unit |
update(params: AppInteractionSession.UpdateParams, executor: Executor, callback: OutcomeReceiver<Void!, AppInteractionException!>)Updates the session with the given |
Constants
CLOSE_REASON_CALLER_INITIATED
static val CLOSE_REASON_CALLER_INITIATED: Int
The session is closed due to the caller calling close().
Value: 2CLOSE_REASON_TIMEOUT
static val CLOSE_REASON_TIMEOUT: Int
The session is closed due to timeout.
Value: 1CLOSE_REASON_UNKNOWN
static val CLOSE_REASON_UNKNOWN: Int
Unknown reason for the session to be closed.
Value: 0Public methods
addLifecycleListener
fun addLifecycleListener(
executor: Executor,
listener: AppInteractionSession.LifecycleListener
): Unit
Adds a listener to receive session lifecycle events.
| Parameters | |
|---|---|
executor |
Executor: The Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
listener |
AppInteractionSession.LifecycleListener: The LifecycleListener to receive lifecycle events. This value cannot be null. |
close
fun close(): Unit
Closes the session.
| Exceptions | |
|---|---|
java.lang.Exception |
if this resource cannot be closed |
removeLifecycleListener
fun removeLifecycleListener(listener: AppInteractionSession.LifecycleListener): Unit
Removes a previously registered session lifecycle listener.
| Parameters | |
|---|---|
listener |
AppInteractionSession.LifecycleListener: The LifecycleListener that should no longer receive lifecycle events. This value cannot be null. |
update
fun update(
params: AppInteractionSession.UpdateParams,
executor: Executor,
callback: OutcomeReceiver<Void!, AppInteractionException!>
): Unit
Updates the session with the given params.
| Parameters | |
|---|---|
params |
AppInteractionSession.UpdateParams: The parameters to update the session with. This value cannot be null. |
executor |
Executor: The Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
callback |
OutcomeReceiver<Void!, AppInteractionException!>: The OutcomeReceiver to receive the result of the update. This value cannot be null. |