VoiceInteractionSession

open class VoiceInteractionSession : KeyEvent.Callback, ComponentCallbacks2
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 be 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

.
Requires API level 21 (Android 5.0, Lollipop)

Summary

Nested classes

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

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.

Constants
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 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
<init>(context: Context!)

<init>(context: Context!, handler: Handler!)

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

Called when a key down event has occurred.

open Unit

Equivalent to VoiceInteractionService.setDisabledShowContext(int).

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

Called when a long press has occurred.

open Unit

Compute the interesting insets into your UI.

open Unit

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

open Unit

Hide the session's UI, if currently shown.

open Unit

Called by the system when the device configuration changes while your component is running.

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)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

open Unit

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

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

Show the UI for this session.

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 View!

Hook in which to create the session's UI.

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 Context!

Requires API level 23 (Android 6.0, Marshmallow)

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 Unit
dump(prefix: String!, fd: FileDescriptor!, writer: PrintWriter!, args: Array<String!>!)

Print the Service's state into the given stream.

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

Called when the lockscreen was shown.

open Unit
onHandleScreenshot(screenshot: Bitmap?)

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

open LayoutInflater!

Convenience for inflating views.

open Unit

Requires API level 21 (Android 5.0, Lollipop)

open Unit

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

open Unit
setKeepAwake(keepAwake: Boolean)

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

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

Called when the session UI is going to be shown.

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

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.

open Unit

Initiatize a new session.

open Unit

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.

open Unit

Control whether the UI layer for this session is enabled.

open Unit

Ask that a new activity be started for voice interaction.

open Unit

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

open Unit

Finish the session.

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 Dialog!

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

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

Called prior to #onShow before any UI setup has occurred.

open Unit

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

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

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

open Unit

Ask that a new assistant activity be started.

open Unit

Called immediately after stopping to show the session UI.

open Int

Equivalent to VoiceInteractionService.getDisabledShowContext.

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

Called when a key up event has occurred.

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

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

open BooleanArray!

Request to query for what extended commands the session supports.

open Unit
setTheme(theme: Int)

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

open Unit

Last callback to the session as it is being finished.

Inherited functions

Constants

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).
Requires API level 24 (Android 7.0, Nougat)

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

Value: 4

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

Value: 2

Public constructors

<init>

VoiceInteractionSession(context: Context!)

<init>

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

Public methods

onKeyDown

added in API level 21
open fun onKeyDown(keyCode: Int, event: KeyEvent!): Boolean

Called when a key down event has occurred. If you return true, you can first call KeyEvent.startTracking() to have the framework track the event through its #onKeyUp(int, KeyEvent) and also call your #onKeyLongPress(int, KeyEvent) if it occurs. Requires API level 21 (Android 5.0, Lollipop)

Parameters
keyCode Int: The value in event.getKeyCode().
event Int: 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.

setDisabledShowContext

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

Equivalent to VoiceInteractionService.setDisabledShowContext(int).
Requires API level 23 (Android 6.0, Marshmallow)

onKeyLongPress

added in API level 21
open fun onKeyLongPress(keyCode: Int, event: KeyEvent!): Boolean

Called when a long press has occurred. If you return true, the final key up will have KeyEvent#FLAG_CANCELED and KeyEvent#FLAG_CANCELED_LONG_PRESS set. Note that in order to receive this callback, someone in the event change must return true from #onKeyDown and call KeyEvent#startTracking() on the event.
Requires API level 5 (Android 2.0, Eclair) Requires API level 21 (Android 5.0, Lollipop)

Parameters
keyCode Int: The value in event.getKeyCode().
event Int: 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.

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.
Requires API level 23 (Android 6.0, Marshmallow)

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

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

onConfigurationChanged

added in API level 23
open fun onConfigurationChanged(newConfig: Configuration!): Unit

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. Requires API level 23 (Android 6.0, Marshmallow)

Parameters
newConfig Configuration!: The new device configuration.

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.
Requires API level 23 (Android 6.0, Marshmallow)

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

onTrimMemory

added in API level 23
open fun onTrimMemory(level: Int): Unit

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process. This will happen for example when it goes in the background and there is not enough memory to keep as many background processes running as desired. 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 ActivityManager.getMyMemoryState(RunningAppProcessInfo).
Requires API level 14 (Android 4.0, IceCreamSandwich) Requires API level 23 (Android 6.0, Marshmallow)

Parameters
level Int: The context of the trim, giving a hint of the amount of trimming the application may like to perform. Value is android.content.ComponentCallbacks2#TRIM_MEMORY_COMPLETE, android.content.ComponentCallbacks2#TRIM_MEMORY_MODERATE, android.content.ComponentCallbacks2#TRIM_MEMORY_BACKGROUND, android.content.ComponentCallbacks2#TRIM_MEMORY_UI_HIDDEN, android.content.ComponentCallbacks2#TRIM_MEMORY_RUNNING_CRITICAL, android.content.ComponentCallbacks2#TRIM_MEMORY_RUNNING_LOW, or android.content.ComponentCallbacks2#TRIM_MEMORY_RUNNING_MODERATE

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.
Requires API level 23 (Android 6.0, Marshmallow)

Parameters
request VoiceInteractionSession.ConfirmationRequest!: The active request.

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.
Requires API level 23 (Android 6.0, Marshmallow)

Parameters
args Bundle!: Arbitrary arguments that will be propagated #onShow.
flags Bundle!: 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.

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

Parameters
request VoiceInteractionSession.CommandRequest!: The active request.

onCreateContentView

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

Hook in which to create the session's UI.
Requires API level 23 (Android 6.0, Marshmallow)

onHandleAssist

added in API level 23
open fun onHandleAssist(data: Bundle?, structure: AssistStructure?, content: AssistContent?): 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, this method will not be called.
Requires API level 23 (Android 6.0, Marshmallow)

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. This value may be null.
structure Bundle?: 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. This value may be null.
content Bundle?: 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. This value may be null.

getContext

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

Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

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

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.
Requires API level 21 (Android 5.0, Lollipop)

onLockscreenShown

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

Called when the lockscreen was shown.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

Parameters
screenshot Bitmap?: This value may be null.

getLayoutInflater

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

Convenience for inflating views.
Requires API level 23 (Android 6.0, Marshmallow)

setContentView

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

Requires API level 21 (Android 5.0, Lollipop)

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, or the client has provided corrupt data. This will be called immediately before #onHandleAssist and the AssistStructure supplied there afterwards will be null.
Requires API level 23 (Android 6.0, Marshmallow)

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

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.


Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 23 (Android 6.0, Marshmallow)

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

onKeyMultiple

added in API level 21
open fun onKeyMultiple(keyCode: Int, count: Int, event: KeyEvent!): Boolean

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. Requires API level 21 (Android 5.0, Lollipop)

Parameters
keyCode Int: The value in event.getKeyCode().
count Int: Number of pairs as returned by event.getRepeatCount().
event Int: 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.

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.
Requires API level 23 (Android 6.0, Marshmallow)

onLowMemory

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

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.

You should implement this method to release any caches or other unnecessary resources you may be holding on to. The system will perform a garbage collection for you after returning from this method.

Preferably, you should implement ComponentCallbacks2#onTrimMemory from ComponentCallbacks2 to incrementally unload your resources based on various levels of memory demands. That API is available for API level 14 and higher, so you should only use this #onLowMemory method as a fallback for older versions, which can be treated the same as ComponentCallbacks2#onTrimMemory with the level.

Requires API level 23 (Android 6.0, Marshmallow)

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().
Requires API level 26 (Android 8.0, Oreo)

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.

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.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 21 (Android 5.0, Lollipop)

onHandleAssistSecondary

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

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.
Requires API level 24 (Android 7.0, Nougat)

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. This value may be null.
structure Bundle?: 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. This value may be null.
content Bundle?: 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. This value may be null.
index Bundle?: the index of the additional activity that this data is for.
count Bundle?: the total number of additional activities for which the assist data is being returned, including the focused activity that is returned via #onHandleAssist.

getWindow

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

Retrieve the window being used to show the session's UI.
Requires API level 23 (Android 6.0, Marshmallow)

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.
Requires API level 26 (Android 8.0, Oreo)

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

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.
Requires API level 23 (Android 6.0, Marshmallow)

Parameters
request VoiceInteractionSession.CompleteVoiceRequest!: The active request.

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.
Requires API level 23 (Android 6.0, Marshmallow)

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

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.
Requires API level 23 (Android 6.0, Marshmallow)

Parameters
request VoiceInteractionSession.PickOptionRequest!: The active request.

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(Bundle, int).


Requires API level 26 (Android 8.0, Oreo)

onHide

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

Called immediately after stopping to show the session UI.
Requires API level 23 (Android 6.0, Marshmallow)

getDisabledShowContext

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

Equivalent to VoiceInteractionService.getDisabledShowContext.
Requires API level 23 (Android 6.0, Marshmallow)

onKeyUp

added in API level 21
open fun onKeyUp(keyCode: Int, event: KeyEvent!): Boolean

Called when a key up event has occurred. Requires API level 21 (Android 5.0, Lollipop)

Parameters
keyCode Int: The value in event.getKeyCode().
event Int: 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.

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.
Requires API level 23 (Android 6.0, Marshmallow)

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

onGetSupportedCommands

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

Request to query for what extended commands the session supports.
Requires API level 23 (Android 6.0, Marshmallow)

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.

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.
Requires API level 23 (Android 6.0, Marshmallow)

onDestroy

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

Last callback to the session as it is being finished.
Requires API level 21 (Android 5.0, Lollipop)