Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#nestedclasses) \| [Constants](https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#constants) \| [Inherited Constants](https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#inhconstants) \| [Ctors](https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#pubctors) \| [Methods](https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#inhmethods)

# VoiceInteractionSession

*** ** * ** ***

` public class VoiceInteractionSession `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/content/ComponentCallbacks2, https://developer.android.com/reference/android/view/KeyEvent.Callback `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.service.voice.VoiceInteractionSession |

<br />

*** ** * ** ***

An active voice interaction session, providing a facility for the implementation to interact with the user in the voice interaction layer. The user interface is initially shown by default, and can be created by overriding `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCreateContentView()` in which the UI can be built.

A voice interaction session can be self-contained, ultimately calling `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#finish()` when done. It can also initiate voice interactions with applications by calling `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)`
.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AbortVoiceRequest` A request to report that the current user interaction can not be completed with voice, as per `https://developer.android.com/reference/android/app/VoiceInteractor.AbortVoiceRequest`. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId` Represents the id of an assist source activity. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AssistState` Represents assist state captured when this session was started. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.CommandRequest` A generic vendor-specific request, as per `https://developer.android.com/reference/android/app/VoiceInteractor.CommandRequest`. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.CompleteVoiceRequest` A request to simply inform the user that the voice operation has completed, as per `https://developer.android.com/reference/android/app/VoiceInteractor.CompleteVoiceRequest`. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ConfirmationRequest` A request for confirmation from the user of an operation, as per `https://developer.android.com/reference/android/app/VoiceInteractor.ConfirmationRequest`. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Insets` Information about where interesting parts of the input method UI appear. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.PickOptionRequest` A request for the user to pick from a set of option, as per `https://developer.android.com/reference/android/app/VoiceInteractor.PickOptionRequest`. |
| ` class` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Request` Base class representing a request from a voice-driver app to perform a particular voice operation with the user. |
| ` interface` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.VisibleActivityCallback` Callback interface for receiving visible activity changes used for assistant usage. |

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#KEY_FOREGROUND_ACTIVITIES` Bundle key used to specify foreground activity app components. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#KEY_SHOW_SESSION_ID` Bundle key used to specify the id when the system prepares to show session. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_SOURCE_ACTIVITY` Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that an Activity has invoked the voice interaction service for a local interaction using `https://developer.android.com/reference/android/app/Activity#startLocalVoiceInteraction(android.os.Bundle)`. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_SOURCE_APPLICATION` Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the application itself has invoked the assistant. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_SOURCE_ASSIST_GESTURE` Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the session has been started from the system assist gesture. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_SOURCE_AUTOMOTIVE_SYSTEM_UI` Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the voice interaction service was invoked from an Android automotive system UI. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_SOURCE_NOTIFICATION` Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the voice interaction service was invoked from a notification. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_SOURCE_PUSH_TO_TALK` Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the voice interaction service was invoked from a physical button. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST` Flag received in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: originator requested that the session be started with assist data from the currently focused activity. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST_STRUCTURE_SCREEN_CONTENT` Flag received in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: originator requested that the session be started with included screen content in the AssistStructure. |
| `int` | `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_SCREENSHOT` Flag received in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: originator requested that the session be started with a screen shot of the currently focused activity. |

### Inherited constants

From interface `https://developer.android.com/reference/android/content/ComponentCallbacks2` `int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_BACKGROUND`

Level for `https://developer.android.com/reference/android/content/ComponentCallbacks2#onTrimMemory(int)`: the process has gone on to the LRU list.
`int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_COMPLETE`

*This constant was deprecated in API level 35. Apps are not notified of this level since API level 34*
`int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_MODERATE`

*This constant was deprecated in API level 35. Apps are not notified of this level since API level 34*
`int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_RUNNING_CRITICAL`

*This constant was deprecated in API level 35. Apps are not notified of this level since API level 34*
`int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_RUNNING_LOW`

*This constant was deprecated in API level 35. Apps are not notified of this level since API level 34*
`int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_RUNNING_MODERATE`

*This constant was deprecated in API level 35. Apps are not notified of this level since API level 34*
`int` `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_UI_HIDDEN`

Level for `https://developer.android.com/reference/android/content/ComponentCallbacks2#onTrimMemory(int)`: the process had been showing a user interface, and is no longer doing so.

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#VoiceInteractionSession(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` |
| ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#VoiceInteractionSession(android.content.Context,%20android.os.Handler)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/os/Handler handler) ` |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#closeSystemDialogs()() ` Request that all system dialogs (and status bar shade etc) be closed, allowing access to the session's UI. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#dump(java.lang.String,%20java.io.FileDescriptor,%20java.io.PrintWriter,%20java.lang.String[])(https://developer.android.com/reference/java/lang/String prefix, https://developer.android.com/reference/java/io/FileDescriptor fd, https://developer.android.com/reference/java/io/PrintWriter writer, https://developer.android.com/reference/java/lang/String args) ` Print the Service's state into the given stream. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#finish()() ` Finish the session. |
| ` https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#getAppFunctionActivityId(android.service.voice.VoiceInteractionSession.ActivityId)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId activityId) ` Converts a `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId` to an `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId`. |
| ` https://developer.android.com/reference/android/content/Context` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#getContext()() ` |
| ` int` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#getDisabledShowContext()() ` Equivalent to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#getDisabledShowContext()`. |
| ` https://developer.android.com/reference/android/view/LayoutInflater` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#getLayoutInflater()() ` Convenience for inflating views. |
| ` int` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#getUserDisabledShowContext()() ` Return which show context flags have been disabled by the user through the system settings UI, so the session will never get this data. |
| ` https://developer.android.com/reference/android/app/Dialog` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#getWindow()() ` Retrieve the window being used to show the session's UI. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#hide()() ` Hide the session's UI, if currently shown. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onAssistStructureFailure(java.lang.Throwable)(https://developer.android.com/reference/java/lang/Throwable failure) ` Called when there has been a failure transferring the `https://developer.android.com/reference/android/app/assist/AssistStructure` to the assistant. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onBackPressed()() ` Called when the user presses the back button while focus is in the session UI. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCancelRequest(android.service.voice.VoiceInteractionSession.Request)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Request request) ` Called when the `https://developer.android.com/reference/android/app/VoiceInteractor` has asked to cancel a `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Request` that was previously delivered to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestConfirmation(android.service.voice.VoiceInteractionSession.ConfirmationRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestPickOption(android.service.voice.VoiceInteractionSession.PickOptionRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCompleteVoice(android.service.voice.VoiceInteractionSession.CompleteVoiceRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestAbortVoice(android.service.voice.VoiceInteractionSession.AbortVoiceRequest)`, or `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCommand(android.service.voice.VoiceInteractionSession.CommandRequest)`. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCloseSystemDialogs()() ` Sessions automatically watch for requests that all system UI be closed (such as when the user presses HOME), which will appear here. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onComputeInsets(android.service.voice.VoiceInteractionSession.Insets)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Insets outInsets) ` Compute the interesting insets into your UI. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onConfigurationChanged(android.content.res.Configuration)(https://developer.android.com/reference/android/content/res/Configuration newConfig) ` Called by the system when the device configuration changes while your component is running. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCreate()() ` Initiatize a new session. |
| ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCreateContentView()() ` Hook in which to create the session's UI. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onDestroy()() ` Last callback to the session as it is being finished. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onDirectActionsInvalidated(android.service.voice.VoiceInteractionSession.ActivityId)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId activityId) ` Called when the direct actions are invalidated. |
| ` boolean[]` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onGetSupportedCommands(java.lang.String[])(https://developer.android.com/reference/java/lang/String commands) ` Request to query for what extended commands the session supports. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.os.Bundle,%20android.app.assist.AssistStructure,%20android.app.assist.AssistContent)(https://developer.android.com/reference/android/os/Bundle data, https://developer.android.com/reference/android/app/assist/AssistStructure structure, https://developer.android.com/reference/android/app/assist/AssistContent content) ` *This method was deprecated in API level 29. use `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.service.voice.VoiceInteractionSession.AssistState)`* |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.service.voice.VoiceInteractionSession.AssistState)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AssistState state) ` Called to receive data from the application that the user was currently viewing when an assist session is started. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssistSecondary(android.os.Bundle,%20android.app.assist.AssistStructure,%20android.app.assist.AssistContent,%20int,%20int)(https://developer.android.com/reference/android/os/Bundle data, https://developer.android.com/reference/android/app/assist/AssistStructure structure, https://developer.android.com/reference/android/app/assist/AssistContent content, int index, int count) ` *This method was deprecated in API level 29. use `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.service.voice.VoiceInteractionSession.AssistState)`* |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleScreenshot(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap screenshot) ` Called to receive a screenshot of what the user was currently viewing when an assist session is started. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHide()() ` Called immediately after stopping to show the session UI. |
| ` boolean` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onKeyDown(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key down event has occurred. |
| ` boolean` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onKeyLongPress(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a long press has occurred. |
| ` boolean` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onKeyMultiple(int,%20int,%20android.view.KeyEvent)(int keyCode, int count, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession. |
| ` boolean` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onKeyUp(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) ` Called when a key up event has occurred. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onLockscreenShown()() ` Called when the lockscreen was shown. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onLowMemory()() ` This is called when the overall system is running low on memory, and actively running processes should trim their memory usage. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onPrepareShow(android.os.Bundle,%20int)(https://developer.android.com/reference/android/os/Bundle args, int showFlags) ` Called prior to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)` before any UI setup has occurred. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestAbortVoice(android.service.voice.VoiceInteractionSession.AbortVoiceRequest)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AbortVoiceRequest request) ` Request to abort the voice interaction session because the voice activity can not complete its interaction using voice. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCommand(android.service.voice.VoiceInteractionSession.CommandRequest)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.CommandRequest request) ` Process an arbitrary extended command from the caller, corresponding to a `https://developer.android.com/reference/android/app/VoiceInteractor.CommandRequest`. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCompleteVoice(android.service.voice.VoiceInteractionSession.CompleteVoiceRequest)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.CompleteVoiceRequest request) ` Request to complete the voice interaction session because the voice activity successfully completed its interaction using voice. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestConfirmation(android.service.voice.VoiceInteractionSession.ConfirmationRequest)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ConfirmationRequest request) ` Request to confirm with the user before proceeding with an unrecoverable operation, corresponding to a `https://developer.android.com/reference/android/app/VoiceInteractor.ConfirmationRequest`. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestPickOption(android.service.voice.VoiceInteractionSession.PickOptionRequest)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.PickOptionRequest request) ` Request for the user to pick one of N options, corresponding to a `https://developer.android.com/reference/android/app/VoiceInteractor.PickOptionRequest`. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)(https://developer.android.com/reference/android/os/Bundle args, int showFlags) ` Called when the session UI is going to be shown. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onTaskFinished(android.content.Intent,%20int)(https://developer.android.com/reference/android/content/Intent intent, int taskId) ` Called when the last activity of a task initiated by `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)` has finished. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onTaskStarted(android.content.Intent,%20int)(https://developer.android.com/reference/android/content/Intent intent, int taskId) ` Called when a task initiated by `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)` has actually started. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onTrimMemory(int)(int level) ` Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. |
| ` final void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#performDirectAction(android.app.DirectAction,%20android.os.Bundle,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20java.util.function.Consumer<android.os.Bundle>)(https://developer.android.com/reference/android/app/DirectAction action, https://developer.android.com/reference/android/os/Bundle extras, https://developer.android.com/reference/android/os/CancellationSignal cancellationSignal, https://developer.android.com/reference/java/util/concurrent/Executor resultExecutor, https://developer.android.com/reference/java/util/function/Consumer<https://developer.android.com/reference/android/os/Bundle> resultListener) ` Asks that an action be performed by the app. |
| ` final void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#registerVisibleActivityCallback(java.util.concurrent.Executor,%20android.service.voice.VoiceInteractionSession.VisibleActivityCallback)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.VisibleActivityCallback callback) ` Registers a callback that will be notified when visible activities have been changed. |
| ` final void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#requestDirectActions(android.service.voice.VoiceInteractionSession.ActivityId,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20java.util.function.Consumer<java.util.List<android.app.DirectAction>>)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId activityId, https://developer.android.com/reference/android/os/CancellationSignal cancellationSignal, https://developer.android.com/reference/java/util/concurrent/Executor resultExecutor, https://developer.android.com/reference/java/util/function/Consumer<https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/app/DirectAction>> callback) ` Requests a list of supported actions from an app. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setContentView(android.view.View)(https://developer.android.com/reference/android/view/View view) ` |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setDisabledShowContext(int)(int flags) ` Equivalent to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#setDisabledShowContext(int)`. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setKeepAwake(boolean)(boolean keepAwake) ` Set whether this session will keep the device awake while it is running a voice activity. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setTheme(int)(int theme) ` You can call this to customize the theme used by your IME's window. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setUiEnabled(boolean)(boolean enabled) ` Control whether the UI layer for this session is enabled. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#show(android.os.Bundle,%20int)(https://developer.android.com/reference/android/os/Bundle args, int flags) ` Show the UI for this session. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startAssistantActivity(android.content.Intent,%20android.os.Bundle)(https://developer.android.com/reference/android/content/Intent intent, https://developer.android.com/reference/android/os/Bundle bundle) ` <br /> Ask that a new assistant activity be started. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startAssistantActivity(android.content.Intent)(https://developer.android.com/reference/android/content/Intent intent) ` <br /> Ask that a new assistant activity be started. |
| ` void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)(https://developer.android.com/reference/android/content/Intent intent) ` Ask that a new activity be started for voice interaction. |
| ` final void` | ` https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#unregisterVisibleActivityCallback(android.service.voice.VoiceInteractionSession.VisibleActivityCallback)(https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.VisibleActivityCallback callback) ` Unregisters the callback. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/content/ComponentCallbacks2 ` ` abstract void` ` https://developer.android.com/reference/android/content/ComponentCallbacks2#onTrimMemory(int)(int level) `

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.
From interface ` https://developer.android.com/reference/android/view/KeyEvent.Callback ` ` abstract boolean` ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyDown(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Called when a key down event has occurred.
` abstract boolean` ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyLongPress(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Called when a long press has occurred.
` abstract boolean` ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyMultiple(int,%20int,%20android.view.KeyEvent)(int keyCode, int count, https://developer.android.com/reference/android/view/KeyEvent event) `

Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession.
` abstract boolean` ` https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyUp(int,%20android.view.KeyEvent)(int keyCode, https://developer.android.com/reference/android/view/KeyEvent event) `

Called when a key up event has occurred.
From interface ` https://developer.android.com/reference/android/content/ComponentCallbacks ` ` abstract void` ` https://developer.android.com/reference/android/content/ComponentCallbacks#onConfigurationChanged(android.content.res.Configuration)(https://developer.android.com/reference/android/content/res/Configuration newConfig) `

Called by the system when the device configuration changes while your component is running.
` abstract void` ` https://developer.android.com/reference/android/content/ComponentCallbacks#onLowMemory()() `

*This method was deprecated in API level 35. Since API level 14 this is superseded by `https://developer.android.com/reference/android/content/ComponentCallbacks2#onTrimMemory(int)`. Since API level 34 this is never called. If you're overriding ComponentCallbacks2#onTrimMemory and your minSdkVersion is greater than API 14, you can provide an empty implementation for this method.*

## Constants

### KEY_FOREGROUND_ACTIVITIES

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String KEY_FOREGROUND_ACTIVITIES
```

Bundle key used to specify foreground activity app components.

Type: ArrayList\&ltComponentName\>

<br />

<br />

**See also:**

- `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`

Constant Value: "android.service.voice.FOREGROUND_ACTIVITIES"

### KEY_SHOW_SESSION_ID

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final String KEY_SHOW_SESSION_ID
```

Bundle key used to specify the id when the system prepares to show session. It increases for each request.

Type: int

<br />

<br />

**See also:**

- `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#showSession(android.os.Bundle,%20int)`
- `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#onPrepareToShowSession(android.os.Bundle,%20int)`
- `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#onShowSessionFailed(android.os.Bundle)`
- `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`
- `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#show(android.os.Bundle,%20int)`

Constant Value: "android.service.voice.SHOW_SESSION_ID"

### SHOW_SOURCE_ACTIVITY

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_SOURCE_ACTIVITY
```

Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that an Activity has invoked the voice interaction service for a local interaction using `https://developer.android.com/reference/android/app/Activity#startLocalVoiceInteraction(android.os.Bundle)`.

<br />

Constant Value: 16 (0x00000010)

### SHOW_SOURCE_APPLICATION

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_SOURCE_APPLICATION
```

Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the application itself has invoked the assistant.

<br />

Constant Value: 8 (0x00000008)

### SHOW_SOURCE_ASSIST_GESTURE

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_SOURCE_ASSIST_GESTURE
```

Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the session has been started from the system assist gesture.

<br />

Constant Value: 4 (0x00000004)

### SHOW_SOURCE_AUTOMOTIVE_SYSTEM_UI

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_SOURCE_AUTOMOTIVE_SYSTEM_UI
```

Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the voice interaction service was invoked from an Android automotive system UI.

<br />

Constant Value: 128 (0x00000080)

### SHOW_SOURCE_NOTIFICATION

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_SOURCE_NOTIFICATION
```

Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the voice interaction service was invoked from a notification.

<br />

Constant Value: 64 (0x00000040)

### SHOW_SOURCE_PUSH_TO_TALK

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_SOURCE_PUSH_TO_TALK
```

Flag for use with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: indicates that the voice interaction service was invoked from a physical button.

<br />

Constant Value: 32 (0x00000020)

### SHOW_WITH_ASSIST

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_WITH_ASSIST
```

Flag received in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: originator requested that the session be started with assist data from the currently focused activity.

<br />

Constant Value: 1 (0x00000001)

### SHOW_WITH_ASSIST_STRUCTURE_SCREEN_CONTENT

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_WITH_ASSIST_STRUCTURE_SCREEN_CONTENT
```

Flag received in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: originator requested that the session be started with included screen content in the AssistStructure. NOTE: This flag must be passed along with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST` or it will have no effect, as the new session will not receive any assist data, and thus no `https://developer.android.com/reference/android/app/assist/AssistStructure` will be included.

<br />

Constant Value: 256 (0x00000100)

### SHOW_WITH_SCREENSHOT

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int SHOW_WITH_SCREENSHOT
```

Flag received in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`: originator requested that the session be started with a screen shot of the currently focused activity.

<br />

Constant Value: 2 (0x00000002)

## Public constructors

### VoiceInteractionSession

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VoiceInteractionSession (Context context)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |

### VoiceInteractionSession

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public VoiceInteractionSession (Context context, 
                Handler handler)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `handler` | `Handler` <br /> |

## Public methods

### closeSystemDialogs

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void closeSystemDialogs ()
```

Request that all system dialogs (and status bar shade etc) be closed, allowing access to the session's UI. This will *not* cause the lock screen to be dismissed.

<br />

### dump

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter writer, 
                String[] args)
```

Print the Service's state into the given stream. This gets invoked by `https://developer.android.com/reference/android/service/voice/VoiceInteractionSessionService` when its Service `https://developer.android.com/reference/android/app/Service#dump(java.io.FileDescriptor,%20java.io.PrintWriter,%20java.lang.String[])` method is called.

<br />

| Parameters ||
|---|---|
| `prefix` | `String`: Text to print at the front of each line. <br /> |
| `fd` | `FileDescriptor`: The raw file descriptor that the dump is being sent to. <br /> |
| `writer` | `PrintWriter`: The PrintWriter to which you should dump your state. This will be closed for you after you return. <br /> |
| `args` | `String`: additional arguments to the dump request. <br /> |

### finish

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void finish ()
```

Finish the session. This completely destroys the session -- the next time it is shown, an entirely new one will be created. You do not normally call this function; instead, use `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#hide()` and allow the system to destroy your session if it needs its RAM.

<br />

### getAppFunctionActivityId

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public AppFunctionActivityId getAppFunctionActivityId (VoiceInteractionSession.ActivityId activityId)
```

Converts a `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId` to an `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId`.

The resulting `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId` will equal an element of `https://developer.android.com/reference/android/app/appfunctions/AppFunctionState#getActivityIds()` if they reference the same `https://developer.android.com/reference/android/app/Activity` instance.

<br />

| Parameters ||
|---|---|
| `activityId` | `VoiceInteractionSession.ActivityId`: The `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId` to convert. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId` | The converted `https://developer.android.com/reference/android/app/appfunctions/AppFunctionActivityId`. This value cannot be `null`. <br /> |

### getContext

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Context getContext ()
```

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Context` | <br /> |

### getDisabledShowContext

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getDisabledShowContext ()
```

Equivalent to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#getDisabledShowContext()`.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getLayoutInflater

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public LayoutInflater getLayoutInflater ()
```

Convenience for inflating views.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/LayoutInflater` | <br /> |

### getUserDisabledShowContext

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getUserDisabledShowContext ()
```

Return which show context flags have been disabled by the user through the system settings UI, so the session will never get this data. Returned flags are any combination of `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST` and `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_SCREENSHOT`. Note that this only tells you about global user settings, not about restrictions that may be applied contextual based on the current application the user is in or other transient states.

<br />

| Returns ||
|---|---|
| `int` | <br /> |

### getWindow

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Dialog getWindow ()
```

Retrieve the window being used to show the session's UI.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Dialog` | <br /> |

### hide

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void hide ()
```

Hide the session's UI, if currently shown. Call this when you are done with your user interaction.

<br />

### onAssistStructureFailure

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onAssistStructureFailure (Throwable failure)
```

Called when there has been a failure transferring the `https://developer.android.com/reference/android/app/assist/AssistStructure` to the assistant. This may happen, for example, if the data is too large and results in an out of memory exception, the data has been cleared during transferring due to the new incoming assist data, or the client has provided corrupt data. This will be called immediately before `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.os.Bundle,%20android.app.assist.AssistStructure,%20android.app.assist.AssistContent)` and the AssistStructure supplied there afterwards will be null.

<br />

| Parameters ||
|---|---|
| `failure` | `Throwable`: The failure exception that was thrown when building the `https://developer.android.com/reference/android/app/assist/AssistStructure`. <br /> |

### onBackPressed

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onBackPressed ()
```

Called when the user presses the back button while focus is in the session UI. Note that this will only happen if the session UI has requested input focus in its window; otherwise, the back key will go to whatever window has focus and do whatever behavior it normally has there. The default implementation simply calls `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#hide()`.

<br />

### onCancelRequest

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCancelRequest (VoiceInteractionSession.Request request)
```

Called when the `https://developer.android.com/reference/android/app/VoiceInteractor` has asked to cancel a `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Request` that was previously delivered to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestConfirmation(android.service.voice.VoiceInteractionSession.ConfirmationRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestPickOption(android.service.voice.VoiceInteractionSession.PickOptionRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCompleteVoice(android.service.voice.VoiceInteractionSession.CompleteVoiceRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestAbortVoice(android.service.voice.VoiceInteractionSession.AbortVoiceRequest)`, or `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCommand(android.service.voice.VoiceInteractionSession.CommandRequest)`.

<br />

| Parameters ||
|---|---|
| `request` | `VoiceInteractionSession.Request`: The request that is being canceled. <br /> |

### onCloseSystemDialogs

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCloseSystemDialogs ()
```

Sessions automatically watch for requests that all system UI be closed (such as when the user presses HOME), which will appear here. The default implementation always calls `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#hide()`.

<br />

### onComputeInsets

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onComputeInsets (VoiceInteractionSession.Insets outInsets)
```

Compute the interesting insets into your UI. The default implementation sets `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Insets#contentInsets` to the height of the window, meaning it should not adjust content underneath. The default touchable insets are `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.Insets#TOUCHABLE_INSETS_FRAME`, meaning it consumes all touch events within its window frame.

<br />

| Parameters ||
|---|---|
| `outInsets` | `VoiceInteractionSession.Insets`: Fill in with the current UI insets. <br /> |

### onConfigurationChanged

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onConfigurationChanged (Configuration newConfig)
```

Called by the system when the device configuration changes while your component is running. Note that, unlike activities, other components are never restarted when a configuration changes: they must always deal with the results of the change, such as by re-retrieving resources.

At the time that this function has been called, your Resources object will have been updated to return resource values matching the new configuration.

For more information, read [Handling Runtime Changes](https://developer.android.com/guide/topics/resources/runtime-changes).

<br />

| Parameters ||
|---|---|
| `newConfig` | `Configuration`: The new device configuration. This value cannot be `null`. <br /> |

### onCreate

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onCreate ()
```

Initiatize a new session. At this point you don't know exactly what this session will be used for; you will find that out in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`.

<br />

### onCreateContentView

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public View onCreateContentView ()
```

Hook in which to create the session's UI.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/View` | <br /> |

### onDestroy

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDestroy ()
```

Last callback to the session as it is being finished.

<br />

### onDirectActionsInvalidated

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDirectActionsInvalidated (VoiceInteractionSession.ActivityId activityId)
```

Called when the direct actions are invalidated.

<br />

| Parameters ||
|---|---|
| `activityId` | `VoiceInteractionSession.ActivityId`: This value cannot be `null`. <br /> |

### onGetSupportedCommands

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean[] onGetSupportedCommands (String[] commands)
```

Request to query for what extended commands the session supports.

<br />

| Parameters ||
|---|---|
| `commands` | `String`: An array of commands that are being queried. <br /> |

| Returns ||
|---|---|
| `boolean[]` | Return an array of booleans indicating which of each entry in the command array is supported. A true entry in the array indicates the command is supported; false indicates it is not. The default implementation returns an array of all false entries. <br /> |

### onHandleAssist

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onHandleAssist (Bundle data, 
                AssistStructure structure, 
                AssistContent content)
```

<br />

**This method was deprecated in API level 29.**   

use `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.service.voice.VoiceInteractionSession.AssistState)`

Called to receive data from the application that the user was currently viewing when - \* an assist session is started. If the original show request did not specify `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST`, this method will not be called.

<br />

| Parameters ||
|---|---|
| `data` | `Bundle`: Arbitrary data supplied by the app through `https://developer.android.com/reference/android/app/Activity#onProvideAssistData(android.os.Bundle)`. May be null if assist data has been disabled by the user or device policy. <br /> |
| `structure` | `AssistStructure`: If available, the structure definition of all windows currently displayed by the app. May be null if assist data has been disabled by the user or device policy; will be an empty stub if the application has disabled assist by marking its window as secure. <br /> |
| `content` | `AssistContent`: Additional content data supplied by the app through `https://developer.android.com/reference/android/app/Activity#onProvideAssistContent(android.app.assist.AssistContent)`. May be null if assist data has been disabled by the user or device policy; will not be automatically filled in with data from the app if the app has marked its window as secure. <br /> |

### onHandleAssist

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onHandleAssist (VoiceInteractionSession.AssistState state)
```

Called to receive data from the application that the user was currently viewing when an assist session is started. If the original show request did not specify `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AssistState` parameter will only provide `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.ActivityId`. If there was a failure to write the assist data to `https://developer.android.com/reference/android/app/assist/AssistStructure`, the `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AssistState#getAssistStructure()` will return null.

This method is called for all activities along with an index and count that indicates which activity the data is for. `index` will be between 0 and `count`-1 and this method is called once for each activity in no particular order. The `count` indicates how many activities to expect assist data for, including the top focused one. The focused activity can be determined by calling `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.AssistState#isFocused()`.

To be responsive to assist requests, process assist data as soon as it is received, without waiting for all queued activities to return assist data.

<br />

| Parameters ||
|---|---|
| `state` | `VoiceInteractionSession.AssistState`: The state object capturing the state of an activity. This value cannot be `null`. <br /> |

### onHandleAssistSecondary

Added in [API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onHandleAssistSecondary (Bundle data, 
                AssistStructure structure, 
                AssistContent content, 
                int index, 
                int count)
```

<br />

**This method was deprecated in API level 29.**   

use `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.service.voice.VoiceInteractionSession.AssistState)`

Called to receive data from other applications that the user was or is interacting with, that are currently on the screen in a multi-window display environment, not including the currently focused activity. This could be a free-form window, a picture-in-picture window, or another window in a split-screen display.

This method is very similar to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.os.Bundle,%20android.app.assist.AssistStructure,%20android.app.assist.AssistContent)` except that it is called for additional non-focused activities along with an index and count that indicates which additional activity the data is for. `index` will be between 1 and `count`-1 and this method is called once for each additional window, in no particular order. The `count` indicates how many windows to expect assist data for, including the top focused activity, which continues to be returned via `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.os.Bundle,%20android.app.assist.AssistStructure,%20android.app.assist.AssistContent)`.

To be responsive to assist requests, process assist data as soon as it is received, without waiting for all queued activities to return assist data.

<br />

| Parameters ||
|---|---|
| `data` | `Bundle`: Arbitrary data supplied by the app through `https://developer.android.com/reference/android/app/Activity#onProvideAssistData(android.os.Bundle)`. May be null if assist data has been disabled by the user or device policy. <br /> |
| `structure` | `AssistStructure`: If available, the structure definition of all windows currently displayed by the app. May be null if assist data has been disabled by the user or device policy; will be an empty stub if the application has disabled assist by marking its window as secure. <br /> |
| `content` | `AssistContent`: Additional content data supplied by the app through `https://developer.android.com/reference/android/app/Activity#onProvideAssistContent(android.app.assist.AssistContent)`. May be null if assist data has been disabled by the user or device policy; will not be automatically filled in with data from the app if the app has marked its window as secure. <br /> |
| `index` | `int`: the index of the additional activity that this data is for. <br /> |
| `count` | `int`: the total number of additional activities for which the assist data is being returned, including the focused activity that is returned via `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onHandleAssist(android.os.Bundle,%20android.app.assist.AssistStructure,%20android.app.assist.AssistContent)`. <br /> |

### onHandleScreenshot

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onHandleScreenshot (Bitmap screenshot)
```

Called to receive a screenshot of what the user was currently viewing when an assist session is started. May be null if screenshots are disabled by the user, policy, or application. If the original show request did not specify `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_SCREENSHOT`, this method will not be called.

<br />

| Parameters ||
|---|---|
| `screenshot` | `Bitmap`: This value may be `null`. <br /> |

### onHide

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onHide ()
```

Called immediately after stopping to show the session UI.

<br />

### onKeyDown

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean onKeyDown (int keyCode, 
                KeyEvent event)
```

Called when a key down event has occurred. If you return true, you can first call `https://developer.android.com/reference/android/view/KeyEvent#startTracking()` to have the framework track the event through its `https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyUp(int,%20android.view.KeyEvent)` and also call your `https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyLongPress(int,%20android.view.KeyEvent)` if it occurs.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `event` | `KeyEvent`: Description of the key event. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onKeyLongPress

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean onKeyLongPress (int keyCode, 
                KeyEvent event)
```

Called when a long press has occurred. If you return true, the final key up will have `https://developer.android.com/reference/android/view/KeyEvent#FLAG_CANCELED` and `https://developer.android.com/reference/android/view/KeyEvent#FLAG_CANCELED_LONG_PRESS` set. Note that in order to receive this callback, someone in the event change *must* return true from `https://developer.android.com/reference/android/view/KeyEvent.Callback#onKeyDown(int,%20android.view.KeyEvent)` *and* call `https://developer.android.com/reference/android/view/KeyEvent#startTracking()` on the event.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `event` | `KeyEvent`: Description of the key event. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onKeyMultiple

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean onKeyMultiple (int keyCode, 
                int count, 
                KeyEvent event)
```

Called when a user's interaction with an analog control, such as flinging a trackball, generates simulated down/up events for the same key multiple times in quick succession.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `count` | `int`: Number of pairs as returned by event.getRepeatCount(). <br /> |
| `event` | `KeyEvent`: Description of the key event. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onKeyUp

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean onKeyUp (int keyCode, 
                KeyEvent event)
```

Called when a key up event has occurred.

<br />

| Parameters ||
|---|---|
| `keyCode` | `int`: The value in event.getKeyCode(). <br /> |
| `event` | `KeyEvent`: Description of the key event. <br /> |

| Returns ||
|---|---|
| `boolean` | If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false. <br /> |

### onLockscreenShown

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onLockscreenShown ()
```

Called when the lockscreen was shown.

<br />

### onLowMemory

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onLowMemory ()
```

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage. While the exact point at which this will be called is not defined, generally it will happen when all background process have been killed. That is, before reaching the point of killing processes hosting service and foreground UI that we would like to avoid killing.

<br />

### onPrepareShow

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onPrepareShow (Bundle args, 
                int showFlags)
```

Called prior to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)` before any UI setup has occurred. Not generally useful.

<br />

| Parameters ||
|---|---|
| `args` | `Bundle`: The arguments that were supplied to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#showSession(android.os.Bundle,%20int)`. <br /> |
| `showFlags` | `int`: The show flags originally provided to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#showSession(android.os.Bundle,%20int)`. <br /> |

### onRequestAbortVoice

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRequestAbortVoice (VoiceInteractionSession.AbortVoiceRequest request)
```

Request to abort the voice interaction session because the voice activity can not complete its interaction using voice. Corresponds to `https://developer.android.com/reference/android/app/VoiceInteractor.AbortVoiceRequest`. The default implementation just sends an empty confirmation back to allow the activity to exit.

<br />

| Parameters ||
|---|---|
| `request` | `VoiceInteractionSession.AbortVoiceRequest`: The active request. <br /> |

### onRequestCommand

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRequestCommand (VoiceInteractionSession.CommandRequest request)
```

Process an arbitrary extended command from the caller, corresponding to a `https://developer.android.com/reference/android/app/VoiceInteractor.CommandRequest`.

<br />

| Parameters ||
|---|---|
| `request` | `VoiceInteractionSession.CommandRequest`: The active request. <br /> |

### onRequestCompleteVoice

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRequestCompleteVoice (VoiceInteractionSession.CompleteVoiceRequest request)
```

Request to complete the voice interaction session because the voice activity successfully completed its interaction using voice. Corresponds to `https://developer.android.com/reference/android/app/VoiceInteractor.CompleteVoiceRequest`. The default implementation just sends an empty confirmation back to allow the activity to exit.

<br />

| Parameters ||
|---|---|
| `request` | `VoiceInteractionSession.CompleteVoiceRequest`: The active request. <br /> |

### onRequestConfirmation

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRequestConfirmation (VoiceInteractionSession.ConfirmationRequest request)
```

Request to confirm with the user before proceeding with an unrecoverable operation, corresponding to a `https://developer.android.com/reference/android/app/VoiceInteractor.ConfirmationRequest`.

<br />

| Parameters ||
|---|---|
| `request` | `VoiceInteractionSession.ConfirmationRequest`: The active request. <br /> |

### onRequestPickOption

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onRequestPickOption (VoiceInteractionSession.PickOptionRequest request)
```

Request for the user to pick one of N options, corresponding to a `https://developer.android.com/reference/android/app/VoiceInteractor.PickOptionRequest`.

<br />

| Parameters ||
|---|---|
| `request` | `VoiceInteractionSession.PickOptionRequest`: The active request. <br /> |

### onShow

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onShow (Bundle args, 
                int showFlags)
```

Called when the session UI is going to be shown. This is called after `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCreateContentView()` (if the session's content UI needed to be created) and immediately prior to the window being shown. This may be called while the window is already shown, if a show request has come in while it is shown, to allow you to update the UI to match the new show arguments.

<br />

| Parameters ||
|---|---|
| `args` | `Bundle`: The arguments that were supplied to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#showSession(android.os.Bundle,%20int)`. Some example keys include : - invocation_type - invocation_phone_state - `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#KEY_SHOW_SESSION_ID` - invocation_time_ms - Intent.EXTRA_TIME ("android.intent.extra.TIME") indicating timing in milliseconds of the KeyEvent that triggered Assistant - Intent.EXTRA_ASSIST_INPUT_DEVICE_ID (android.intent.extra.ASSIST_INPUT_DEVICE_ID) referring to the device that sent the request - `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#KEY_FOREGROUND_ACTIVITIES` provides foreground activities of up coming onHandleAssist/onHandleScreenshot calls earlier. This is only populated if session was requested with `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST` show flag. - Starting from Android 14, the system will add `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#KEY_SHOW_SESSION_ID`, the Bundle is not null. But the application should handle null case before Android 14. <br /> |
| `showFlags` | `int`: The show flags originally provided to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#showSession(android.os.Bundle,%20int)`. <br /> |

### onTaskFinished

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onTaskFinished (Intent intent, 
                int taskId)
```

Called when the last activity of a task initiated by `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)` has finished. The default implementation calls `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#finish()` on the assumption that this represents the completion of a voice action. You can override the implementation if you would like a different behavior.

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The original `https://developer.android.com/reference/android/content/Intent` supplied to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)`. <br /> |
| `taskId` | `int`: Unique ID of the finished task. <br /> |

### onTaskStarted

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onTaskStarted (Intent intent, 
                int taskId)
```

Called when a task initiated by `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)` has actually started.

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The original `https://developer.android.com/reference/android/content/Intent` supplied to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)`. <br /> |
| `taskId` | `int`: Unique ID of the now running task. <br /> |

### onTrimMemory

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onTrimMemory (int level)
```

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. You should never compare to exact values of the level, since new intermediate values may be added -- you will typically want to compare if the value is greater or equal to a level you are interested in.

To retrieve the processes current trim level at any point, you can use `https://developer.android.com/reference/android/app/ActivityManager#getMyMemoryState(android.app.ActivityManager.RunningAppProcessInfo)`.

<br />

| Parameters ||
|---|---|
| `level` | `int`: The context of the trim, giving a hint of the amount of trimming the application may like to perform. Value is one of the following: - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_COMPLETE` - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_MODERATE` - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_BACKGROUND` - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_UI_HIDDEN` - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_RUNNING_CRITICAL` - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_RUNNING_LOW` - `https://developer.android.com/reference/android/content/ComponentCallbacks2#TRIM_MEMORY_RUNNING_MODERATE` |

### performDirectAction

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void performDirectAction (DirectAction action, 
                Bundle extras, 
                CancellationSignal cancellationSignal, 
                Executor resultExecutor, 
                Consumer<Bundle> resultListener)
```

Asks that an action be performed by the app. This will send a request to the app which provided this action.

An action could take time to execute and the result is provided asynchronously via a callback. If the action is taking longer and you want to cancel its execution you can pass in a cancellation signal through which to notify the app to abort the action.

<br />

| Parameters ||
|---|---|
| `action` | `DirectAction`: The action to be performed. This value cannot be `null`. <br /> |
| `extras` | `Bundle`: Any optional extras sent to the app as part of the request. This value may be `null`. <br /> |
| `cancellationSignal` | `CancellationSignal`: A signal to cancel the operation in progress, or `null` if none. <br /> |
| `resultExecutor` | `Executor`: The handler to receive the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `resultListener` | `Consumer`: The callback to receive the response. This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#requestDirectActions(android.service.voice.VoiceInteractionSession.ActivityId,%20android.os.CancellationSignal,%20java.util.concurrent.Executor,%20java.util.function.Consumer<java.util.List<android.app.DirectAction>>)`
- `https://developer.android.com/reference/android/app/Activity#onGetDirectActions(android.os.CancellationSignal,%20java.util.function.Consumer<java.util.List<android.app.DirectAction>>)`

### registerVisibleActivityCallback

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void registerVisibleActivityCallback (Executor executor, 
                VoiceInteractionSession.VisibleActivityCallback callback)
```

Registers a callback that will be notified when visible activities have been changed. Note: The `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession.VisibleActivityCallback#onVisible(android.service.voice.VisibleActivityInfo)` will be called immediately with current visible activities when the callback is registered for the first time. If the callback is already registered, this method does nothing.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: The executor which will be used to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `VoiceInteractionSession.VisibleActivityCallback`: The callback to receive the response. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if calling this method before onCreate(). |

### requestDirectActions

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void requestDirectActions (VoiceInteractionSession.ActivityId activityId, 
                CancellationSignal cancellationSignal, 
                Executor resultExecutor, 
                Consumer<List<DirectAction>> callback)
```

Requests a list of supported actions from an app.

<br />

| Parameters ||
|---|---|
| `activityId` | `VoiceInteractionSession.ActivityId`: Ths activity id of the app to get the actions from. This value cannot be `null`. <br /> |
| `cancellationSignal` | `CancellationSignal`: A signal to cancel the operation in progress, or `null` if none. <br /> |
| `resultExecutor` | `Executor`: The handler to receive the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `Consumer`: The callback to receive the response. This value cannot be `null`. <br /> |

### setContentView

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setContentView (View view)
```

<br />

<br />

| Parameters ||
|---|---|
| `view` | `View` <br /> |

### setDisabledShowContext

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDisabledShowContext (int flags)
```

Equivalent to `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#setDisabledShowContext(int)`.

<br />

| Parameters ||
|---|---|
| `flags` | `int` <br /> |

### setKeepAwake

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setKeepAwake (boolean keepAwake)
```

Set whether this session will keep the device awake while it is running a voice activity. By default, the system holds a wake lock for it while in this state, so that it can work even if the screen is off. Setting this to false removes that wake lock, allowing the CPU to go to sleep. This is typically used if the session decides it has been waiting too long for a response from the user and doesn't want to let this continue to drain the battery.

Passing false here will release the wake lock, and you can call later with true to re-acquire it. It will also be automatically re-acquired for you each time you start a new voice activity task -- that is when you call `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startVoiceActivity(android.content.Intent)`.

<br />

<br />

| Parameters ||
|---|---|
| `keepAwake` | `boolean` <br /> |

### setTheme

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setTheme (int theme)
```

You can call this to customize the theme used by your IME's window. This must be set before `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCreate()`, so you will typically call it in your constructor with the resource ID of your custom theme.

<br />

| Parameters ||
|---|---|
| `theme` | `int` <br /> |

### setUiEnabled

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setUiEnabled (boolean enabled)
```

Control whether the UI layer for this session is enabled. It is enabled by default. If set to false, you will not be able to provide a UI through `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onCreateContentView()`.

<br />

| Parameters ||
|---|---|
| `enabled` | `boolean` <br /> |

### show

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void show (Bundle args, 
                int flags)
```

Show the UI for this session. This asks the system to go through the process of showing your UI, which will eventually culminate in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`. This is similar to calling `https://developer.android.com/reference/android/service/voice/VoiceInteractionService#showSession(android.os.Bundle,%20int)`.

<br />

| Parameters ||
|---|---|
| `args` | `Bundle`: Arbitrary arguments that will be propagated `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onShow(android.os.Bundle,%20int)`. <br /> |
| `flags` | `int`: Indicates additional optional behavior that should be performed. May be any combination of `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_ASSIST` and `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#SHOW_WITH_SCREENSHOT` to request that the system generate and deliver assist data on the current foreground app as part of showing the session UI. <br /> |

### startAssistantActivity

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startAssistantActivity (Intent intent, 
                Bundle bundle)
```

<br />

Ask that a new assistant activity be started. This will create a new task in the in activity manager: this means that `https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK` will be set for you to make it a new task.

The newly started activity will be displayed on top of other activities in the system in a new layer that is not affected by multi-window mode. Tasks started from this activity will go into the normal activity layer and not this new layer.

By default, the system will create a window for the UI for this session. If you are using an assistant activity instead, then you can disable the window creation by calling `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setUiEnabled(boolean)` in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onPrepareShow(android.os.Bundle,%20int)`.

<br />

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: the intent used to start an assistant activity. This value cannot be `null`. <br /> |
| `bundle` | `Bundle`: Additional options for how the Activity should be started. See `https://developer.android.com/reference/android/app/ActivityOptions` for how to build the Bundle supplied here. This value cannot be `null`. <br /> |

### startAssistantActivity

Added in [API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startAssistantActivity (Intent intent)
```

<br />

Ask that a new assistant activity be started. This will create a new task in the in activity manager: this means that `https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK` will be set for you to make it a new task.

The newly started activity will be displayed on top of other activities in the system in a new layer that is not affected by multi-window mode. Tasks started from this activity will go into the normal activity layer and not this new layer.

By default, the system will create a window for the UI for this session. If you are using an assistant activity instead, then you can disable the window creation by calling `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#setUiEnabled(boolean)` in `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onPrepareShow(android.os.Bundle,%20int)`.
NOTE: if the app would like to override some options to start the Activity, use `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#startAssistantActivity(android.content.Intent,%20android.os.Bundle)` instead.

<br />

<br />

| Parameters ||
|---|---|
| `intent` | `Intent` <br /> |

### startVoiceActivity

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startVoiceActivity (Intent intent)
```

Ask that a new activity be started for voice interaction. This will create a new dedicated task in the activity manager for this voice interaction session; this means that `https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK` will be set for you to make it a new task.

The newly started activity will be displayed to the user in a special way, as a layer under the voice interaction UI.

As the voice activity runs, it can retrieve a `https://developer.android.com/reference/android/app/VoiceInteractor` through which it can perform voice interactions through your session. These requests for voice interactions will appear as callbacks on `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onGetSupportedCommands(java.lang.String[])`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestConfirmation(android.service.voice.VoiceInteractionSession.ConfirmationRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestPickOption(android.service.voice.VoiceInteractionSession.PickOptionRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCompleteVoice(android.service.voice.VoiceInteractionSession.CompleteVoiceRequest)`, `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestAbortVoice(android.service.voice.VoiceInteractionSession.AbortVoiceRequest)`, or `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onRequestCommand(android.service.voice.VoiceInteractionSession.CommandRequest)`

You will receive a call to `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onTaskStarted(android.content.Intent,%20int)` when the task starts up and `https://developer.android.com/reference/android/service/voice/VoiceInteractionSession#onTaskFinished(android.content.Intent,%20int)` when the last activity has finished.

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The Intent to start this voice interaction. The given Intent will always have `https://developer.android.com/reference/android/content/Intent#CATEGORY_VOICE` added to it, since this is part of a voice interaction. <br /> |

### unregisterVisibleActivityCallback

Added in [API level 32](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public final void unregisterVisibleActivityCallback (VoiceInteractionSession.VisibleActivityCallback callback)
```

Unregisters the callback.

<br />

| Parameters ||
|---|---|
| `callback` | `VoiceInteractionSession.VisibleActivityCallback`: The callback to receive the response. This value cannot be `null`. <br /> |