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)
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
VoiceInteractionSession.AbortVoiceRequest |
A request to report that the current user interaction can not be completed with voice, as per
VoiceInteractor.AbortVoiceRequest .
|
||||||||||
VoiceInteractionSession.CommandRequest |
A generic vendor-specific request, as per
VoiceInteractor.CommandRequest .
|
||||||||||
VoiceInteractionSession.CompleteVoiceRequest |
A request to simply inform the user that the voice operation has completed, as per
VoiceInteractor.CompleteVoiceRequest .
|
||||||||||
VoiceInteractionSession.ConfirmationRequest |
A request for confirmation from the user of an operation, as per
VoiceInteractor.ConfirmationRequest .
|
||||||||||
VoiceInteractionSession.Insets | Information about where interesting parts of the input method UI appear. | ||||||||||
VoiceInteractionSession.PickOptionRequest |
A request for the user to pick from a set of option, as per
VoiceInteractor.PickOptionRequest .
|
||||||||||
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_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.
|
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From interface
android.content.ComponentCallbacks2
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Request that all system dialogs (and status bar shade etc) be closed, allowing
access to the session's UI.
| |||||||||||
Print the Service's state into the given stream.
| |||||||||||
Finish the session.
| |||||||||||
Equivalent to
VoiceInteractionService.getDisabledShowContext .
| |||||||||||
Convenience for inflating views.
| |||||||||||
Return which show context flags have been disabled by the user through the system
settings UI, so the session will never get this data.
| |||||||||||
Retrieve the window being used to show the session's UI.
| |||||||||||
Hide the session's UI, if currently shown.
| |||||||||||
Called when there has been a failure transferring the
AssistStructure to
the assistant.
| |||||||||||
Called when the user presses the back button while focus is in the session UI.
| |||||||||||
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) .
| |||||||||||
Sessions automatically watch for requests that all system UI be closed (such as when
the user presses HOME), which will appear here.
| |||||||||||
Compute the interesting insets into your UI.
| |||||||||||
Called by the system when the device configuration changes while your
component is running.
| |||||||||||
Initiatize a new session.
| |||||||||||
Hook in which to create the session's UI.
| |||||||||||
Last callback to the session as it is being finished.
| |||||||||||
Request to query for what extended commands the session supports.
| |||||||||||
Called to receive data from the application that the user was currently viewing when
an assist session is started.
| |||||||||||
Called to receive a screenshot of what the user was currently viewing when an assist
session is started.
| |||||||||||
Called immediately after stopping to show the session UI.
| |||||||||||
Called when a key down event has occurred.
| |||||||||||
Called when a long press has occurred.
| |||||||||||
Called when multiple down/up pairs of the same key have occurred
in a row.
| |||||||||||
Called when a key up event has occurred.
| |||||||||||
Called when the lockscreen was shown.
| |||||||||||
This is called when the overall system is running low on memory, and
actively running processes should trim their memory usage.
| |||||||||||
Request to abort the voice interaction session because the voice activity can not
complete its interaction using voice.
| |||||||||||
Process an arbitrary extended command from the caller,
corresponding to a
VoiceInteractor.CommandRequest .
| |||||||||||
Request to complete the voice interaction session because the voice activity successfully
completed its interaction using voice.
| |||||||||||
Request to confirm with the user before proceeding with an unrecoverable operation,
corresponding to a
VoiceInteractor.ConfirmationRequest .
| |||||||||||
Request for the user to pick one of N options, corresponding to a
VoiceInteractor.PickOptionRequest .
| |||||||||||
Called when the session UI is going to be shown.
| |||||||||||
Called when the last activity of a task initiated by
startVoiceActivity(android.content.Intent) has finished.
| |||||||||||
Called when a task initiated by
startVoiceActivity(android.content.Intent)
has actually started.
| |||||||||||
Called when the operating system has determined that it is a good
time for a process to trim unneeded memory from its process.
| |||||||||||
Equivalent to
VoiceInteractionService.setDisabledShowContext(int) .
| |||||||||||
Set whether this session will keep the device awake while it is running a voice
activity.
| |||||||||||
You can call this to customize the theme used by your IME's window.
| |||||||||||
Show the UI for this session.
| |||||||||||
Ask that a new activity be started for voice interaction.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
android.view.KeyEvent.Callback
| |||||||||||
From interface
android.content.ComponentCallbacks2
| |||||||||||
From interface
android.content.ComponentCallbacks
|
Flag for use with onShow(Bundle, int)
: indicates that the application itself has invoked
the assistant.
Flag for use with onShow(Bundle, int)
: indicates that the session has been started from the
system assist gesture.
Flag received in onShow(Bundle, int)
: originator requested that the session be started with
assist data from the currently focused activity.
Flag received in onShow(Bundle, int)
: originator requested that the session be started with
a screen shot of the currently focused activity.
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.
Print the Service's state into the given stream. This gets invoked by
VoiceInteractionSessionService
when its Service
dump(FileDescriptor, PrintWriter, String[])
method is called.
prefix | Text to print at the front of each line. |
---|---|
fd | The raw file descriptor that the dump is being sent to. |
writer | The PrintWriter to which you should dump your state. This will be closed for you after you return. |
args | additional arguments to the dump request. |
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.
Equivalent to VoiceInteractionService.getDisabledShowContext
.
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.
Retrieve the window being used to show the session's UI.
Hide the session's UI, if currently shown. Call this when you are done with your user interaction.
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.
failure | The failure exception that was thrown when building the
AssistStructure .
|
---|
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()
.
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)
.
request | The request that is being canceled. |
---|
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()
.
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.
outInsets | Fill in with the current UI insets. |
---|
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.
newConfig | The new device configuration. |
---|
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)
.
Last callback to the session as it is being finished.
Request to query for what extended commands the session supports.
commands | An array of commands that are being queried. |
---|
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.
data | 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 | 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 | 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.
|
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.
Called immediately after stopping to show the session UI.
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.
keyCode | The value in event.getKeyCode(). |
---|---|
event | Description of the key 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.
keyCode | The value in event.getKeyCode(). |
---|---|
event | Description of the key event. |
Called when multiple down/up pairs of the same key have occurred in a row.
keyCode | The value in event.getKeyCode(). |
---|---|
count | Number of pairs as returned by event.getRepeatCount(). |
event | Description of the key event. |
Called when a key up event has occurred.
keyCode | The value in event.getKeyCode(). |
---|---|
event | Description of the key event. |
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.
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.
request | The active request. |
---|
Process an arbitrary extended command from the caller,
corresponding to a VoiceInteractor.CommandRequest
.
request | The active 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.
request | The active request. |
---|
Request to confirm with the user before proceeding with an unrecoverable operation,
corresponding to a VoiceInteractor.ConfirmationRequest
.
request | The active request. |
---|
Request for the user to pick one of N options, corresponding to a
VoiceInteractor.PickOptionRequest
.
request | The active request. |
---|
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.
args | The arguments that were supplied to
VoiceInteractionService.showSession . |
---|---|
showFlags | The show flags originally provided to
VoiceInteractionService.showSession .
|
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.
intent | The original Intent supplied to
startVoiceActivity(android.content.Intent) . |
---|---|
taskId | Unique ID of the finished task. |
Called when a task initiated by startVoiceActivity(android.content.Intent)
has actually started.
intent | The original Intent supplied to
startVoiceActivity(android.content.Intent) . |
---|---|
taskId | Unique ID of the now running task. |
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)
.
level | 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 .
|
---|
Equivalent to VoiceInteractionService.setDisabledShowContext(int)
.
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)
.
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.
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
.
args | Arbitrary arguments that will be propagated onShow(Bundle, int) . |
---|---|
flags | 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.
|
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.
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.
|
---|