Skip to content

Most visited

Recently visited

navigation

VoiceInteractionSession

public class VoiceInteractionSession
extends Object implements KeyEvent.Callback, ComponentCallbacks2

java.lang.Object
   ↳ 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(Intent)

.

Summary

Nested classes

class VoiceInteractionSession.AbortVoiceRequest

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

class VoiceInteractionSession.CommandRequest

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

class VoiceInteractionSession.CompleteVoiceRequest

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

class VoiceInteractionSession.ConfirmationRequest

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

class VoiceInteractionSession.Insets

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

class VoiceInteractionSession.PickOptionRequest

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

class VoiceInteractionSession.Request

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

Constants

int SHOW_SOURCE_ACTIVITY

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

int SHOW_SOURCE_APPLICATION

Flag for use with onShow(Bundle, int): indicates that the application itself has invoked the assistant.

int SHOW_SOURCE_ASSIST_GESTURE

Flag for use with onShow(Bundle, int): indicates that the session has been started from the system assist gesture.

int SHOW_WITH_ASSIST

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

int SHOW_WITH_SCREENSHOT

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

Inherited constants

From interface android.content.ComponentCallbacks2

Public constructors

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

Public methods

void closeSystemDialogs()

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

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

Print the Service's state into the given stream.

void finish()

Finish the session.

Context getContext()
int getDisabledShowContext()

Equivalent to VoiceInteractionService.getDisabledShowContext.

LayoutInflater getLayoutInflater()

Convenience for inflating views.

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.

Dialog getWindow()

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

void hide()

Hide the session's UI, if currently shown.

void onAssistStructureFailure(Throwable failure)

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

void onBackPressed()

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

void onCancelRequest(VoiceInteractionSession.Request request)

Called when the VoiceInteractor has asked to cancel a VoiceInteractionSession.Request that was previously delivered to onRequestConfirmation(VoiceInteractionSession.ConfirmationRequest), onRequestPickOption(VoiceInteractionSession.PickOptionRequest), onRequestCompleteVoice(VoiceInteractionSession.CompleteVoiceRequest), onRequestAbortVoice(VoiceInteractionSession.AbortVoiceRequest), or onRequestCommand(VoiceInteractionSession.CommandRequest).

void onCloseSystemDialogs()

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

void onComputeInsets(VoiceInteractionSession.Insets outInsets)

Compute the interesting insets into your UI.

void onConfigurationChanged(Configuration newConfig)

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

void onCreate()

Initiatize a new session.

View onCreateContentView()

Hook in which to create the session's UI.

void onDestroy()

Last callback to the session as it is being finished.

boolean[] onGetSupportedCommands(String[] commands)

Request to query for what extended commands the session supports.

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

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

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

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.

void onHandleScreenshot(Bitmap screenshot)

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

void onHide()

Called immediately after stopping to show the session UI.

boolean onKeyDown(int keyCode, KeyEvent event)

Called when a key down event has occurred.

boolean onKeyLongPress(int keyCode, KeyEvent event)

Called when a long press has occurred.

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.

boolean onKeyUp(int keyCode, KeyEvent event)

Called when a key up event has occurred.

void onLockscreenShown()

Called when the lockscreen was shown.

void onLowMemory()

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

void onPrepareShow(Bundle args, int showFlags)

Called prior to onShow(Bundle, int) before any UI setup has occurred.

void onRequestAbortVoice(VoiceInteractionSession.AbortVoiceRequest request)

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

void onRequestCommand(VoiceInteractionSession.CommandRequest request)

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

void onRequestCompleteVoice(VoiceInteractionSession.CompleteVoiceRequest request)

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

void onRequestConfirmation(VoiceInteractionSession.ConfirmationRequest request)

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

void onRequestPickOption(VoiceInteractionSession.PickOptionRequest request)

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

void onShow(Bundle args, int showFlags)

Called when the session UI is going to be shown.

void onTaskFinished(Intent intent, int taskId)

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

void onTaskStarted(Intent intent, int taskId)

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

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.

void setContentView(View view)
void setDisabledShowContext(int flags)

Equivalent to VoiceInteractionService.setDisabledShowContext(int).

void setKeepAwake(boolean keepAwake)

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

void setTheme(int theme)

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

void setUiEnabled(boolean enabled)

Control whether the UI layer for this session is enabled.

void show(Bundle args, int flags)

Show the UI for this session.

void startAssistantActivity(Intent intent)

Ask that a new assistant activity be started.

void startVoiceActivity(Intent intent)

Ask that a new activity be started for voice interaction.

Inherited methods

From class java.lang.Object
From interface android.view.KeyEvent.Callback
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

Constants

SHOW_SOURCE_ACTIVITY

added in API level 24
int SHOW_SOURCE_ACTIVITY

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

Constant Value: 16 (0x00000010)

SHOW_SOURCE_APPLICATION

added in API level 23
int SHOW_SOURCE_APPLICATION

Flag for use with onShow(Bundle, int): indicates that the application itself has invoked the assistant.

Constant Value: 8 (0x00000008)

SHOW_SOURCE_ASSIST_GESTURE

added in API level 23
int SHOW_SOURCE_ASSIST_GESTURE

Flag for use with onShow(Bundle, int): indicates that the session has been started from the system assist gesture.

Constant Value: 4 (0x00000004)

SHOW_WITH_ASSIST

added in API level 23
int SHOW_WITH_ASSIST

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

Constant Value: 1 (0x00000001)

SHOW_WITH_SCREENSHOT

added in API level 23
int SHOW_WITH_SCREENSHOT

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

Constant Value: 2 (0x00000002)

Public constructors

VoiceInteractionSession

added in API level 21
VoiceInteractionSession (Context context)

Parameters
context Context

VoiceInteractionSession

added in API level 21
VoiceInteractionSession (Context context, 
                Handler handler)

Parameters
context Context
handler Handler

Public methods

closeSystemDialogs

added in API level 23
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.

dump

added in API level 23
void dump (String prefix, 
                FileDescriptor fd, 
                PrintWriter writer, 
                String[] args)

Print the Service's state into the given stream. This gets invoked by VoiceInteractionSessionService when its Service dump(FileDescriptor, PrintWriter, String[]) 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 String: additional arguments to the dump request.

finish

added in API level 21
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 hide() and allow the system to destroy your session if it needs its RAM.

getContext

added in API level 23
Context getContext ()

Returns
Context

getDisabledShowContext

added in API level 23
int getDisabledShowContext ()

Equivalent to VoiceInteractionService.getDisabledShowContext.

Returns
int

getLayoutInflater

added in API level 23
LayoutInflater getLayoutInflater ()

Convenience for inflating views.

Returns
LayoutInflater

getUserDisabledShowContext

added in API level 23
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 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.

Returns
int

getWindow

added in API level 23
Dialog getWindow ()

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

Returns
Dialog

hide

added in API level 23
void hide ()

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

onAssistStructureFailure

added in API level 23
void onAssistStructureFailure (Throwable failure)

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(Bundle, AssistStructure, AssistContent) 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
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 hide().

onCloseSystemDialogs

added in API level 21
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 hide().

onComputeInsets

added in API level 23
void onComputeInsets (VoiceInteractionSession.Insets outInsets)

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

Parameters
newConfig Configuration: The new device configuration.

onCreate

added in API level 23
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 onShow(Bundle, int).

onCreateContentView

added in API level 23
View onCreateContentView ()

Hook in which to create the session's UI.

Returns
View

onDestroy

added in API level 21
void onDestroy ()

Last callback to the session as it is being finished.

onGetSupportedCommands

added in API level 23
boolean[] onGetSupportedCommands (String[] commands)

Request to query for what extended commands the session supports.

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

onHandleAssist

added in API level 23
void onHandleAssist (Bundle data, 
                AssistStructure structure, 
                AssistContent content)

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.

onHandleAssistSecondary

added in API level 24
void onHandleAssistSecondary (Bundle data, 
                AssistStructure structure, 
                AssistContent content, 
                int index, 
                int count)

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(Bundle, AssistStructure, 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 onHandleAssist(Bundle, AssistStructure, 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.

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

onHandleScreenshot

added in API level 23
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 SHOW_WITH_SCREENSHOT, this method will not be called.

Parameters
screenshot Bitmap

onHide

added in API level 23
void onHide ()

Called immediately after stopping to show the session UI.

onKeyDown

added in API level 21
boolean onKeyDown (int keyCode, 
                KeyEvent event)

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.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
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.

onKeyLongPress

added in API level 21
boolean onKeyLongPress (int keyCode, 
                KeyEvent event)

Called when a long press has occurred. If you return true, the final key up will have FLAG_CANCELED and FLAG_CANCELED_LONG_PRESS set. Note that in order to receive this callback, someone in the event change must return true from onKeyDown(int, KeyEvent) and call startTracking() on the event.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
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.

onKeyMultiple

added in API level 21
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.

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

onKeyUp

added in API level 21
boolean onKeyUp (int keyCode, 
                KeyEvent event)

Called when a key up event has occurred.

Parameters
keyCode int: The value in event.getKeyCode().
event KeyEvent: Description of the key event.
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.

onLockscreenShown

added in API level 23
void onLockscreenShown ()

Called when the lockscreen was shown.

onLowMemory

added in API level 23
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.

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 onTrimMemory(int) 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 onTrimMemory(int) with the TRIM_MEMORY_COMPLETE level.

onPrepareShow

void onPrepareShow (Bundle args, 
                int showFlags)

Called prior to onShow(Bundle, int) 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
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 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
void onRequestCommand (VoiceInteractionSession.CommandRequest request)

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
void onRequestCompleteVoice (VoiceInteractionSession.CompleteVoiceRequest request)

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
void onRequestConfirmation (VoiceInteractionSession.ConfirmationRequest request)

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
void onRequestPickOption (VoiceInteractionSession.PickOptionRequest request)

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
void onShow (Bundle args, 
                int showFlags)

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.
showFlags int: The show flags originally provided to VoiceInteractionService.showSession.

onTaskFinished

added in API level 23
void onTaskFinished (Intent intent, 
                int taskId)

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
void onTaskStarted (Intent intent, 
                int taskId)

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.

onTrimMemory

added in API level 23
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. 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).

Parameters
level int: The context of the trim, giving a hint of the amount of trimming the application may like to perform. May be TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_UI_HIDDEN, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, or TRIM_MEMORY_RUNNING_MODERATE.

setContentView

added in API level 21
void setContentView (View view)

Parameters
view View

setDisabledShowContext

added in API level 23
void setDisabledShowContext (int flags)

Equivalent to VoiceInteractionService.setDisabledShowContext(int).

Parameters
flags int

setKeepAwake

added in API level 23
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 startVoiceActivity(Intent).

Parameters
keepAwake boolean

setTheme

added in API level 23
void setTheme (int theme)

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.

Parameters
theme int

setUiEnabled

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

Parameters
enabled boolean

show

added in API level 23
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 onShow(Bundle, int). This is similar to calling VoiceInteractionService.showSession.

Parameters
args Bundle: Arbitrary arguments that will be propagated onShow(Bundle, int).
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

void startAssistantActivity (Intent intent)

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

Parameters
intent Intent

startVoiceActivity

added in API level 23
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 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 VoiceInteractor through which it can perform voice interactions through your session. These requests for voice interactions will appear as callbacks on onGetSupportedCommands(String[]), onRequestConfirmation(VoiceInteractionSession.ConfirmationRequest), onRequestPickOption(VoiceInteractionSession.PickOptionRequest), onRequestCompleteVoice(VoiceInteractionSession.CompleteVoiceRequest), onRequestAbortVoice(VoiceInteractionSession.AbortVoiceRequest), or onRequestCommand(VoiceInteractionSession.CommandRequest)

You will receive a call to onTaskStarted(Intent, int) when the task starts up and onTaskFinished(Intent, int) 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.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a one-minute survey?
Help us improve Android tools and documentation.