public final class VoiceInteractor extends Object
Activity
to interact with the user through voice. Use
Activity.getVoiceInteractor
to retrieve the interface, if the activity is currently involved in a voice interaction.
The voice interactor revolves around submitting voice interaction requests to the
back-end voice interaction service that is working with the user. These requests are
submitted with submitRequest(android.app.VoiceInteractor.Request)
, providing a new instance of a
VoiceInteractor.Request
subclass describing the type of operation to perform -- currently the
possible requests are VoiceInteractor.ConfirmationRequest
and VoiceInteractor.CommandRequest
.
Once a request is submitted, the voice system will process it and eventually deliver the result to the request object. The application can cancel a pending request at any time.
The VoiceInteractor is integrated with Activity's state saving mechanism, so that
if an activity is being restarted with retained state, it will retain the current
VoiceInteractor and any outstanding requests. Because of this, you should always use
Request.getActivity
to get back to the activity of a
request, rather than holding on to the activity instance yourself, either explicitly
or implicitly through a non-static inner class.
Modifier and Type | Class and Description |
---|---|
static class |
VoiceInteractor.AbortVoiceRequest
Reports that the current interaction can not be complete with voice, so the
application will need to switch to a traditional input UI.
|
static class |
VoiceInteractor.CommandRequest
Execute a vendor-specific command using the trusted system VoiceInteractionService.
|
static class |
VoiceInteractor.CompleteVoiceRequest
Reports that the current interaction was successfully completed with voice, so the
application can report the final status to the user.
|
static class |
VoiceInteractor.ConfirmationRequest
Confirms an operation with the user via the trusted system
VoiceInteractionService.
|
static class |
VoiceInteractor.PickOptionRequest
Select a single option from multiple potential options with the user via the trusted system
VoiceInteractionService.
|
static class |
VoiceInteractor.Prompt
A set of voice prompts to use with the voice interaction system to confirm an action, select
an option, or do similar operations.
|
static class |
VoiceInteractor.Request
Base class for voice interaction requests that can be submitted to the interactor.
|
Modifier and Type | Method and Description |
---|---|
VoiceInteractor.Request |
getActiveRequest(String name)
Return any currently active request that was submitted with the given name.
|
VoiceInteractor.Request[] |
getActiveRequests()
Return all currently active requests.
|
boolean |
submitRequest(VoiceInteractor.Request request) |
boolean |
submitRequest(VoiceInteractor.Request request,
String name)
Submit a new
VoiceInteractor.Request to the voice interaction service. |
boolean[] |
supportsCommands(String[] commands)
Queries the supported commands available from the VoiceInteractionService.
|
public boolean submitRequest(VoiceInteractor.Request request)
public boolean submitRequest(VoiceInteractor.Request request, String name)
VoiceInteractor.Request
to the voice interaction service. The request must be
one of the available subclasses -- VoiceInteractor.ConfirmationRequest
, VoiceInteractor.PickOptionRequest
,
VoiceInteractor.CompleteVoiceRequest
, VoiceInteractor.AbortVoiceRequest
, or VoiceInteractor.CommandRequest
.request
- The desired request to submit.name
- An optional name for this request, or null. This can be used later with
getActiveRequests()
and getActiveRequest(java.lang.String)
to find the request.public VoiceInteractor.Request[] getActiveRequests()
public VoiceInteractor.Request getActiveRequest(String name)
name
- The name used to submit the request, as per
submitRequest(android.app.VoiceInteractor.Request, String)
.public boolean[] supportsCommands(String[] commands)
commands
- The array of commands to query for support.