Added in API level 21

VoiceInteractionSession


open class VoiceInteractionSession : ComponentCallbacks2, KeyEvent.Callback
kotlin.Any
   ↳ android.service.voice.VoiceInteractionSession

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 onCreateContentView() in which the UI can be built.

A voice interaction session can be self-contained, ultimately calling finish when done. It can also initiate voice interactions with applications by calling startVoiceActivity

.

Summary

Nested classes

A request to report that the current user interaction can not be completed with voice, as per VoiceInteractor.AbortVoiceRequest.

open

Represents the id of an assist source activity.

Represents assist state captured when this session was started.

A generic vendor-specific request, as per VoiceInteractor.CommandRequest.

A request to simply inform the user that the voice operation has completed, as per VoiceInteractor.CompleteVoiceRequest.

A request for confirmation from the user of an operation, as per VoiceInteractor.ConfirmationRequest.

Information about where interesting parts of the input method UI appear.

A request for the user to pick from a set of option, as per VoiceInteractor.PickOptionRequest.

open

Base class representing a request from a voice-driver app to perform a particular voice operation with the user.

abstract

Callback interface for receiving visible activity changes used for assistant usage.

Constants
static String

Bundle key used to specify foreground activity app components.

static String

Bundle key used to specify the id when the system prepares to show session.

static Int

Flag for use with onShow: indicates that an Activity has invoked the voice interaction service for a local interaction using Activity.startLocalVoiceInteraction(Bundle).

static Int

Flag for use with onShow: indicates that the application itself has invoked the assistant.

static Int

Flag for use with onShow: indicates that the session has been started from the system assist gesture.

static Int

Flag for use with onShow: indicates that the voice interaction service was invoked from an Android automotive system UI.

static Int

Flag for use with onShow: indicates that the voice interaction service was invoked from a notification.

static Int

Flag for use with onShow: indicates that the voice interaction service was invoked from a physical button.

static Int

Flag received in onShow: originator requested that the session be started with assist data from the currently focused activity.

static Int

Flag received in onShow: originator requested that the session be started with a screen shot of the currently focused activity.

Inherited constants
Public constructors

VoiceInteractionSession(context: Context!, handler: Handler!)

Public methods
open Unit

Request that all system dialogs (and status bar shade etc) be closed, allowing access to the session's UI.

open Unit
dump(prefix: String!, fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!)

Print the Service's state into the given stream.

open Unit

Finish the session.

open Context!

open Int

Equivalent to VoiceInteractionService.getDisabledShowContext.

open LayoutInflater!

Convenience for inflating views.

open Int

Return which show context flags have been disabled by the user through the system settings UI, so the session will never get this data.

open Dialog!

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

open Unit

Hide the session's UI, if currently shown.

open Unit

Called when there has been a failure transferring the AssistStructure to the assistant.

open Unit

Called when the user presses the back button while focus is in the session UI.

open Unit

Called when the android.app.VoiceInteractor has asked to cancel a Request that was previously delivered to onRequestConfirmation, onRequestPickOption, onRequestCompleteVoice, onRequestAbortVoice, or onRequestCommand.

open Unit

Sessions automatically watch for requests that all system UI be closed (such as when the user presses HOME), which will appear here.

open Unit

Compute the interesting insets into your UI.

open Unit

open Unit

Initiatize a new session.

open View!

Hook in which to create the session's UI.

open Unit

Last callback to the session as it is being finished.

open Unit

Called when the direct actions are invalidated.

open BooleanArray!

Request to query for what extended commands the session supports.

open Unit
onHandleAssist(data: Bundle?, structure: AssistStructure?, content: AssistContent?)

Called to receive data from the application that the user was currently viewing when - * an assist session is started.

open Unit

Called to receive data from the application that the user was currently viewing when an assist session is started.

open Unit
onHandleAssistSecondary(data: Bundle?, structure: AssistStructure?, content: AssistContent?, index: Int, count: Int)

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.

open Unit
onHandleScreenshot(screenshot: Bitmap?)

Called to receive a screenshot of what the user was currently viewing when an assist session is started.

open Unit

Called immediately after stopping to show the session UI.

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyLongPress(keyCode: Int, event: KeyEvent!)

open Boolean
onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent!)

open Boolean
onKeyUp(keyCode: Int, event: KeyEvent!)

open Unit

Called when the lockscreen was shown.

open Unit

open Unit
onPrepareShow(args: Bundle!, showFlags: Int)

Called prior to onShow before any UI setup has occurred.

open Unit

Request to abort the voice interaction session because the voice activity can not complete its interaction using voice.

open Unit

Process an arbitrary extended command from the caller, corresponding to a VoiceInteractor.CommandRequest.

open Unit

Request to complete the voice interaction session because the voice activity successfully completed its interaction using voice.

open Unit

Request to confirm with the user before proceeding with an unrecoverable operation, corresponding to a VoiceInteractor.ConfirmationRequest.

open Unit

Request for the user to pick one of N options, corresponding to a VoiceInteractor.PickOptionRequest.

open Unit
onShow(args: Bundle?, showFlags: Int)

Called when the session UI is going to be shown.

open Unit
onTaskFinished(intent: Intent!, taskId: Int)

Called when the last activity of a task initiated by startVoiceActivity(android.content.Intent) has finished.

open Unit
onTaskStarted(intent: Intent!, taskId: Int)

Called when a task initiated by startVoiceActivity(android.content.Intent) has actually started.

open Unit
onTrimMemory(level: Int)

Unit
performDirectAction(action: DirectAction, extras: Bundle?, cancellationSignal: CancellationSignal?, resultExecutor: Executor, resultListener: Consumer<Bundle!>)

Asks that an action be performed by the app.

Unit

Registers a callback that will be notified when visible activities have been changed.

Unit
requestDirectActions(activityId: VoiceInteractionSession.ActivityId, cancellationSignal: CancellationSignal?, resultExecutor: Executor, callback: Consumer<MutableList<DirectAction!>!>)

Requests a list of supported actions from an app.

open Unit

open Unit

Equivalent to VoiceInteractionService.setDisabledShowContext(int).

open Unit
setKeepAwake(keepAwake: Boolean)

Set whether this session will keep the device awake while it is running a voice activity.

open Unit
setTheme(theme: Int)

You can call this to customize the theme used by your IME's window.

open Unit

Control whether the UI layer for this session is enabled.

open Unit
show(args: Bundle!, flags: Int)

Show the UI for this session.

open Unit

Ask that a new assistant activity be started.

open Unit

Ask that a new assistant activity be started.

open Unit

Ask that a new activity be started for voice interaction.

Unit

Unregisters the callback.

Inherited functions

Constants

KEY_FOREGROUND_ACTIVITIES

Added in API level 35
static val KEY_FOREGROUND_ACTIVITIES: String

Bundle key used to specify foreground activity app components.

Type: ArrayList&ltComponentName>

Value: "android.service.voice.FOREGROUND_ACTIVITIES"

KEY_SHOW_SESSION_ID

Added in API level 34
static val KEY_SHOW_SESSION_ID: String

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

Type: int

Value: "android.service.voice.SHOW_SESSION_ID"

SHOW_SOURCE_ACTIVITY

Added in API level 24
static val SHOW_SOURCE_ACTIVITY: Int

Flag for use with onShow: indicates that an Activity has invoked the voice interaction service for a local interaction using Activity.startLocalVoiceInteraction(Bundle).

Value: 16

SHOW_SOURCE_APPLICATION

Added in API level 23
static val SHOW_SOURCE_APPLICATION: Int

Flag for use with onShow: indicates that the application itself has invoked the assistant.

Value: 8

SHOW_SOURCE_ASSIST_GESTURE

Added in API level 23
static val SHOW_SOURCE_ASSIST_GESTURE: Int

Flag for use with onShow: indicates that the session has been started from the system assist gesture.

Value: 4

SHOW_SOURCE_AUTOMOTIVE_SYSTEM_UI

Added in API level 29
static val SHOW_SOURCE_AUTOMOTIVE_SYSTEM_UI: Int

Flag for use with onShow: indicates that the voice interaction service was invoked from an Android automotive system UI.

Value: 128

SHOW_SOURCE_NOTIFICATION

Added in API level 29
static val SHOW_SOURCE_NOTIFICATION: Int

Flag for use with onShow: indicates that the voice interaction service was invoked from a notification.

Value: 64

SHOW_SOURCE_PUSH_TO_TALK

Added in API level 29
static val SHOW_SOURCE_PUSH_TO_TALK: Int

Flag for use with onShow: indicates that the voice interaction service was invoked from a physical button.

Value: 32

SHOW_WITH_ASSIST

Added in API level 23
static val SHOW_WITH_ASSIST: Int

Flag received in onShow: originator requested that the session be started with assist data from the currently focused activity.

Value: 1

SHOW_WITH_SCREENSHOT

Added in API level 23
static val SHOW_WITH_SCREENSHOT: Int

Flag received in onShow: originator requested that the session be started with a screen shot of the currently focused activity.

Value: 2

Public constructors

VoiceInteractionSession

Added in API level 21
VoiceInteractionSession(context: Context!)

VoiceInteractionSession

Added in API level 21
VoiceInteractionSession(
    context: Context!,
    handler: Handler!)

Public methods

closeSystemDialogs

Added in API level 23
open fun closeSystemDialogs(): Unit

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.

dump

Added in API level 23
open fun dump(
    prefix: String!,
    fd: FileDescriptor!,
    writer: PrintWriter!,
    args: Array<String!>!
): Unit

Print the Service's state into the given stream. This gets invoked by VoiceInteractionSessionService when its Service android.app.Service#dump method is called.

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

finish

Added in API level 21
open fun finish(): Unit

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 hide and allow the system to destroy your session if it needs its RAM.

getContext

Added in API level 23
open fun getContext(): Context!

getDisabledShowContext

Added in API level 23
open fun getDisabledShowContext(): Int

Equivalent to VoiceInteractionService.getDisabledShowContext.

getLayoutInflater

Added in API level 23
open fun getLayoutInflater(): LayoutInflater!

Convenience for inflating views.

getUserDisabledShowContext

Added in API level 23
open fun getUserDisabledShowContext(): Int

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 VoiceInteractionSession.SHOW_WITH_ASSIST and 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.

getWindow

Added in API level 23
open fun getWindow(): Dialog!

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

hide

Added in API level 23
open fun hide(): Unit

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

onAssistStructureFailure

Added in API level 23
open fun onAssistStructureFailure(failure: Throwable!): Unit

Called when there has been a failure transferring the 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 #onHandleAssist and the AssistStructure supplied there afterwards will be null.

Parameters
failure Throwable!: The failure exception that was thrown when building the AssistStructure.

onBackPressed

Added in API level 23
open fun onBackPressed(): Unit

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

onCancelRequest

Added in API level 23
open fun onCancelRequest(request: VoiceInteractionSession.Request!): Unit

Called when the android.app.VoiceInteractor has asked to cancel a Request that was previously delivered to onRequestConfirmation, onRequestPickOption, onRequestCompleteVoice, onRequestAbortVoice, or onRequestCommand.

Parameters
request VoiceInteractionSession.Request!: The request that is being canceled.

onCloseSystemDialogs

Added in API level 21
open fun onCloseSystemDialogs(): Unit

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

onComputeInsets

Added in API level 23
open fun onComputeInsets(outInsets: VoiceInteractionSession.Insets!): Unit

Compute the interesting insets into your UI. The default implementation sets outInsets.contentInsets.top to the height of the window, meaning it should not adjust content underneath. The default touchable insets are Insets.TOUCHABLE_INSETS_FRAME, meaning it consumes all touch events within its window frame.

Parameters
outInsets VoiceInteractionSession.Insets!: Fill in with the current UI insets.

onConfigurationChanged

Added in API level 23
open fun onConfigurationChanged(newConfig: Configuration): Unit
Parameters
newConfig Configuration: The new device configuration. This value cannot be null.

onCreate

Added in API level 23
open fun onCreate(): Unit

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

onCreateContentView

Added in API level 23
open fun onCreateContentView(): View!

Hook in which to create the session's UI.

onDestroy

Added in API level 21
open fun onDestroy(): Unit

Last callback to the session as it is being finished.

onDirectActionsInvalidated

Added in API level 29
open fun onDirectActionsInvalidated(activityId: VoiceInteractionSession.ActivityId): Unit

Called when the direct actions are invalidated.

Parameters
activityId VoiceInteractionSession.ActivityId: This value cannot be null.

onGetSupportedCommands

Added in API level 23
open fun onGetSupportedCommands(commands: Array<String!>!): BooleanArray!

Request to query for what extended commands the session supports.

Parameters
commands Array<String!>!: An array of commands that are being queried.
Return
BooleanArray! 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.

onHandleAssist

Added in API level 23
Deprecated in API level 29
open fun onHandleAssist(
    data: Bundle?,
    structure: AssistStructure?,
    content: AssistContent?
): Unit

Deprecated: use 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 SHOW_WITH_ASSIST, this method will not be called.

Parameters
data Bundle?: Arbitrary data supplied by the app through Activity.onProvideAssistData. May be null if assist data has been disabled by the user or device policy.
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.
content AssistContent?: Additional content data supplied by the app through Activity.onProvideAssistContent. 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.

onHandleAssist

Added in API level 29
open fun onHandleAssist(state: VoiceInteractionSession.AssistState): Unit

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 SHOW_WITH_ASSIST, AssistState parameter will only provide ActivityId. If there was a failure to write the assist data to AssistStructure, the 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 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.

Parameters
state VoiceInteractionSession.AssistState: The state object capturing the state of an activity. This value cannot be null.

onHandleAssistSecondary

Added in API level 24
Deprecated in API level 29
open fun onHandleAssistSecondary(
    data: Bundle?,
    structure: AssistStructure?,
    content: AssistContent?,
    index: Int,
    count: Int
): Unit

Deprecated: use 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 #onHandleAssist 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 #onHandleAssist.

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.

Parameters
data Bundle?: Arbitrary data supplied by the app through Activity.onProvideAssistData. May be null if assist data has been disabled by the user or device policy.
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.
content AssistContent?: Additional content data supplied by the app through Activity.onProvideAssistContent. 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.
index Int: the index of the additional activity that this data is for.
count Int: the total number of additional activities for which the assist data is being returned, including the focused activity that is returned via #onHandleAssist.

onHandleScreenshot

Added in API level 23
open fun onHandleScreenshot(screenshot: Bitmap?): Unit

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 SHOW_WITH_SCREENSHOT, this method will not be called.

Parameters
screenshot Bitmap?: This value may be null.

onHide

Added in API level 23
open fun onHide(): Unit

Called immediately after stopping to show the session UI.

onKeyDown

Added in API level 21
open fun onKeyDown(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyLongPress

Added in API level 21
open fun onKeyLongPress(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyMultiple

Added in API level 21
open fun onKeyMultiple(
    keyCode: Int,
    count: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: The value in event.getKeyCode().
count Int: Number of pairs as returned by event.getRepeatCount().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onKeyUp

Added in API level 21
open fun onKeyUp(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: The value in event.getKeyCode().
event KeyEvent!: Description of the key event.
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onLockscreenShown

Added in API level 23
open fun onLockscreenShown(): Unit

Called when the lockscreen was shown.

onLowMemory

Added in API level 23
open fun onLowMemory(): Unit

onPrepareShow

Added in API level 26
open fun onPrepareShow(
    args: Bundle!,
    showFlags: Int
): Unit

Called prior to onShow before any UI setup has occurred. Not generally useful.

Parameters
args Bundle!: The arguments that were supplied to VoiceInteractionService.showSession.
showFlags Int: The show flags originally provided to VoiceInteractionService.showSession.

onRequestAbortVoice

Added in API level 23
open fun onRequestAbortVoice(request: VoiceInteractionSession.AbortVoiceRequest!): Unit

Request to abort the voice interaction session because the voice activity can not complete its interaction using voice. Corresponds to VoiceInteractor.AbortVoiceRequest. The default implementation just sends an empty confirmation back to allow the activity to exit.

Parameters
request VoiceInteractionSession.AbortVoiceRequest!: The active request.

onRequestCommand

Added in API level 23
open fun onRequestCommand(request: VoiceInteractionSession.CommandRequest!): Unit

Process an arbitrary extended command from the caller, corresponding to a VoiceInteractor.CommandRequest.

Parameters
request VoiceInteractionSession.CommandRequest!: The active request.

onRequestCompleteVoice

Added in API level 23
open fun onRequestCompleteVoice(request: VoiceInteractionSession.CompleteVoiceRequest!): Unit

Request to complete the voice interaction session because the voice activity successfully completed its interaction using voice. Corresponds to VoiceInteractor.CompleteVoiceRequest. The default implementation just sends an empty confirmation back to allow the activity to exit.

Parameters
request VoiceInteractionSession.CompleteVoiceRequest!: The active request.

onRequestConfirmation

Added in API level 23
open fun onRequestConfirmation(request: VoiceInteractionSession.ConfirmationRequest!): Unit

Request to confirm with the user before proceeding with an unrecoverable operation, corresponding to a VoiceInteractor.ConfirmationRequest.

Parameters
request VoiceInteractionSession.ConfirmationRequest!: The active request.

onRequestPickOption

Added in API level 23
open fun onRequestPickOption(request: VoiceInteractionSession.PickOptionRequest!): Unit

Request for the user to pick one of N options, corresponding to a VoiceInteractor.PickOptionRequest.

Parameters
request VoiceInteractionSession.PickOptionRequest!: The active request.

onShow

Added in API level 23
open fun onShow(
    args: Bundle?,
    showFlags: Int
): Unit

Called when the session UI is going to be shown. This is called after 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.

Parameters
args Bundle?: The arguments that were supplied to VoiceInteractionService.showSession. Some example keys include :
  • invocation_type
  • invocation_phone_state
  • 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
  • KEY_FOREGROUND_ACTIVITIES provides foreground activities of up coming onHandleAssist/onHandleScreenshot calls earlier. This is only populated if session was requested with VoiceInteractionSession.SHOW_WITH_ASSIST show flag.
  • Starting from Android 14, the system will add KEY_SHOW_SESSION_ID, the Bundle is not null. But the application should handle null case before Android 14.
showFlags Int: The show flags originally provided to VoiceInteractionService.showSession.

onTaskFinished

Added in API level 23
open fun onTaskFinished(
    intent: Intent!,
    taskId: Int
): Unit

Called when the last activity of a task initiated by startVoiceActivity(android.content.Intent) has finished. The default implementation calls 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.

Parameters
intent Intent!: The original Intent supplied to startVoiceActivity(android.content.Intent).
taskId Int: Unique ID of the finished task.

onTaskStarted

Added in API level 23
open fun onTaskStarted(
    intent: Intent!,
    taskId: Int
): Unit

Called when a task initiated by startVoiceActivity(android.content.Intent) has actually started.

Parameters
intent Intent!: The original Intent supplied to startVoiceActivity(android.content.Intent).
taskId Int: Unique ID of the now running task.

performDirectAction

Added in API level 29
fun performDirectAction(
    action: DirectAction,
    extras: Bundle?,
    cancellationSignal: CancellationSignal?,
    resultExecutor: Executor,
    resultListener: Consumer<Bundle!>
): Unit

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.

Parameters
action DirectAction: The action to be performed. This value cannot be null.
extras Bundle?: Any optional extras sent to the app as part of the request This value may be null.
cancellationSignal CancellationSignal?: A signal to cancel the operation in progress, or null if none.
resultExecutor Executor: The handler to receive 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.
resultListener Consumer<Bundle!>: The callback to receive the response. This value cannot be null.

registerVisibleActivityCallback

Added in API level 32
fun registerVisibleActivityCallback(
    executor: Executor,
    callback: VoiceInteractionSession.VisibleActivityCallback
): Unit

Registers a callback that will be notified when visible activities have been changed. Note: The VisibleActivityCallback.onVisible(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.

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 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 VoiceInteractionSession.VisibleActivityCallback: The callback to receive the response. This value cannot be null.
Exceptions
java.lang.IllegalStateException if calling this method before onCreate().

requestDirectActions

Added in API level 29
fun requestDirectActions(
    activityId: VoiceInteractionSession.ActivityId,
    cancellationSignal: CancellationSignal?,
    resultExecutor: Executor,
    callback: Consumer<MutableList<DirectAction!>!>
): Unit

Requests a list of supported actions from an app.

Parameters
activityId VoiceInteractionSession.ActivityId: Ths activity id of the app to get the actions from. This value cannot be null.
cancellationSignal CancellationSignal?: A signal to cancel the operation in progress, or null if none.
resultExecutor Executor: The handler to receive 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 Consumer<MutableList<DirectAction!>!>: The callback to receive the response. This value cannot be null.

setContentView

Added in API level 21
open fun setContentView(view: View!): Unit

setDisabledShowContext

Added in API level 23
open fun setDisabledShowContext(flags: Int): Unit

Equivalent to VoiceInteractionService.setDisabledShowContext(int).

setKeepAwake

Added in API level 23
open fun setKeepAwake(keepAwake: Boolean): Unit

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

setTheme

Added in API level 23
open fun setTheme(theme: Int): Unit

You can call this to customize the theme used by your IME's window. This must be set before onCreate, so you will typically call it in your constructor with the resource ID of your custom theme.

setUiEnabled

Added in API level 26
open fun setUiEnabled(enabled: Boolean): Unit

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 onCreateContentView().

show

Added in API level 23
open fun show(
    args: Bundle!,
    flags: Int
): Unit

Show the UI for this session. This asks the system to go through the process of showing your UI, which will eventually culminate in onShow. This is similar to calling VoiceInteractionService.showSession.

Parameters
args Bundle!: Arbitrary arguments that will be propagated onShow.
flags Int: Indicates additional optional behavior that should be performed. May be any combination of VoiceInteractionSession.SHOW_WITH_ASSIST and 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.

startAssistantActivity

Added in API level 26
open fun startAssistantActivity(intent: Intent!): Unit

Ask that a new assistant activity be started. This will create a new task in the in activity manager: this means that 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 setUiEnabled in onPrepareShow(android.os.Bundle,int).

NOTE: if the app would like to override some options to start the Activity, use startAssistantActivity(android.content.Intent,android.os.Bundle) instead.

startAssistantActivity

Added in API level 34
open fun startAssistantActivity(
    intent: Intent,
    bundle: Bundle
): Unit

Ask that a new assistant activity be started. This will create a new task in the in activity manager: this means that 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 setUiEnabled in onPrepareShow(android.os.Bundle,int).

Parameters
intent Intent: the intent used to start an assistant activity This value cannot be null.
bundle Bundle: Additional options for how the Activity should be started. See ActivityOptions for how to build the Bundle supplied here. This value cannot be null.

startVoiceActivity

Added in API level 23
open fun startVoiceActivity(intent: Intent!): Unit

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 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 android.app.VoiceInteractor through which it can perform voice interactions through your session. These requests for voice interactions will appear as callbacks on onGetSupportedCommands, onRequestConfirmation, onRequestPickOption, onRequestCompleteVoice, onRequestAbortVoice, or onRequestCommand

You will receive a call to onTaskStarted when the task starts up and onTaskFinished when the last activity has finished.

Parameters
intent Intent!: The Intent to start this voice interaction. The given Intent will always have Intent.CATEGORY_VOICE added to it, since this is part of a voice interaction.

unregisterVisibleActivityCallback

Added in API level 32
fun unregisterVisibleActivityCallback(callback: VoiceInteractionSession.VisibleActivityCallback): Unit

Unregisters the callback.

Parameters
callback VoiceInteractionSession.VisibleActivityCallback: The callback to receive the response. This value cannot be null.