Android APIs
public class

VoiceInteractionService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ android.service.voice.VoiceInteractionService

Class Overview

Top-level service of the current global voice interactor, which is providing support for hotwording, the back-end of a VoiceInteractor, etc. The current VoiceInteractionService that has been selected by the user is kept always running by the system, to allow it to do things like listen for hotwords in the background to instigate voice interactions.

Because this service is always running, it should be kept as lightweight as possible. Heavy-weight operations (including showing UI) should be implemented in the associated VoiceInteractionSessionService when an actual voice interaction is taking place, and that service should run in a separate process from this one.

Summary

Constants
String SERVICE_INTERFACE The Intent that must be declared as handled by the service.
String SERVICE_META_DATA Name under which a VoiceInteractionService component publishes information about itself.
[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2
Public Constructors
VoiceInteractionService()
Public Methods
final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback)
Creates an AlwaysOnHotwordDetector for the given keyphrase and locale.
int getDisabledShowContext()
Return the value set by setDisabledShowContext(int).
static boolean isActiveService(Context context, ComponentName service)
Check whether the given service component is the currently active VoiceInteractionService.
IBinder onBind(Intent intent)
Return the communication channel to the service.
void onCreate()
Called by the system when the service is first created.
void onLaunchVoiceAssistFromKeyguard()
Called when a user has activated an affordance to launch voice assist from the Keyguard.
void onReady()
Called during service initialization to tell you when the system is ready to receive interaction from it.
void onShutdown()
Called during service de-initialization to tell you when the system is shutting the service down.
void setDisabledShowContext(int flags)
Set contextual options you would always like to have disabled when a session is shown.
void showSession(Bundle args, int flags)
Request that the associated VoiceInteractionSession be shown to the user, starting it if necessary.
Protected Methods
void dump(FileDescriptor fd, PrintWriter pw, String[] args)
Print the Service's state into the given stream.
[Expand]
Inherited Methods
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks2
From interface android.content.ComponentCallbacks

Constants

public static final String SERVICE_INTERFACE

Added in API level 21

The Intent that must be declared as handled by the service. To be supported, the service must also require the BIND_VOICE_INTERACTION permission so that other applications can not abuse it.

Constant Value: "android.service.voice.VoiceInteractionService"

public static final String SERVICE_META_DATA

Added in API level 21

Name under which a VoiceInteractionService component publishes information about itself. This meta-data should reference an XML resource containing a <voice-interaction-service> tag.

Constant Value: "android.voice_interaction"

Public Constructors

public VoiceInteractionService ()

Added in API level 21

Public Methods

public final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector (String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback)

Added in API level 21

Creates an AlwaysOnHotwordDetector for the given keyphrase and locale. This instance must be retained and used by the client. Calling this a second time invalidates the previously created hotword detector which can no longer be used to manage recognition.

Parameters
keyphrase The keyphrase that's being used, for example "Hello Android".
locale The locale for which the enrollment needs to be performed.
callback The callback to notify of detection events.
Returns
  • An always-on hotword detector for the given keyphrase and locale.

public int getDisabledShowContext ()

Added in API level 23

Return the value set by setDisabledShowContext(int).

public static boolean isActiveService (Context context, ComponentName service)

Added in API level 21

Check whether the given service component is the currently active VoiceInteractionService.

public IBinder onBind (Intent intent)

Added in API level 21

Return the communication channel to the service. May return null if clients can not bind to the service. The returned IBinder is usually for a complex interface that has been described using aidl.

Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.

Parameters
intent The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Returns
  • Return an IBinder through which clients can call on to the service.

public void onCreate ()

Added in API level 21

Called by the system when the service is first created. Do not call this method directly.

public void onLaunchVoiceAssistFromKeyguard ()

Added in API level 23

Called when a user has activated an affordance to launch voice assist from the Keyguard.

This method will only be called if the VoiceInteractionService has set supportsLaunchVoiceAssistFromKeyguard and the Keyguard is showing.

A valid implementation must start a new activity that should use FLAG_SHOW_WHEN_LOCKED to display on top of the lock screen.

public void onReady ()

Added in API level 21

Called during service initialization to tell you when the system is ready to receive interaction from it. You should generally do initialization here rather than in onCreate(). Methods such as showSession(Bundle, int) and createAlwaysOnHotwordDetector(String, Locale, AlwaysOnHotwordDetector.Callback) will not be operational until this point.

public void onShutdown ()

Added in API level 21

Called during service de-initialization to tell you when the system is shutting the service down. At this point this service may no longer be the active VoiceInteractionService.

public void setDisabledShowContext (int flags)

Added in API level 23

Set contextual options you would always like to have disabled when a session is shown. The flags may be any combination of VoiceInteractionSession.SHOW_WITH_ASSIST and VoiceInteractionSession.SHOW_WITH_SCREENSHOT.

public void showSession (Bundle args, int flags)

Added in API level 23

Request that the associated VoiceInteractionSession be shown to the user, starting it if necessary.

Parameters
args Arbitrary arguments that will be propagated to the session.
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.

Protected Methods

protected void dump (FileDescriptor fd, PrintWriter pw, String[] args)

Added in API level 21

Print the Service's state into the given stream. This gets invoked if you run "adb shell dumpsys activity service <yourservicename>" (note that for this command to work, the service must be running, and you must specify a fully-qualified service name). This is distinct from "dumpsys <servicename>", which only works for named system services and which invokes the dump(FileDescriptor, String[]) method on the IBinder interface registered with ServiceManager.

Parameters
fd The raw file descriptor that the dump is being sent to.
pw 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.