Added in API level 21

VoiceInteractionService

open class VoiceInteractionService : Service
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ android.service.voice.VoiceInteractionService

Top-level service of the current global voice interactor, which is providing support for hotwording, the back-end of a android.app.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 android.service.voice.VoiceInteractionSessionService when an actual voice interaction is taking place, and that service should run in a separate process from this one.

Summary

Constants
static String

The Intent that must be declared as handled by the service.

static String

Name under which a VoiceInteractionService component publishes information about itself.

Inherited constants
Public constructors

Public methods
open Int

Return the value set by setDisabledShowContext.

open static Boolean
isActiveService(context: Context!, service: ComponentName!)

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

open IBinder?
onBind(intent: Intent!)

open MutableSet<String!>

Request to query for what extended voice actions this service supports.

open Unit

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

open Unit

Notify the interactor when the system prepares to show session.

open Unit

Called during service initialization to tell you when the system is ready to receive interaction from it.

open Unit

Called when the show session failed.

open Unit

Called during service de-initialization to tell you when the system is shutting the service down.

open Unit

Set contextual options you would always like to have disabled when a session is shown.

Unit

Provide hints to be reflected in the system UI.

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

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

Protected methods
open Unit
dump(fd: FileDescriptor!, pw: PrintWriter!, args: Array<String!>!)

Inherited functions

Constants

SERVICE_INTERFACE

Added in API level 21
static val SERVICE_INTERFACE: String

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

Value: "android.service.voice.VoiceInteractionService"

SERVICE_META_DATA

Added in API level 21
static val SERVICE_META_DATA: String

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

Value: "android.voice_interaction"

Public constructors

VoiceInteractionService

VoiceInteractionService()

Public methods

getDisabledShowContext

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

Return the value set by setDisabledShowContext.

isActiveService

Added in API level 21
open static fun isActiveService(
    context: Context!,
    service: ComponentName!
): Boolean

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

onBind

Added in API level 21
open fun onBind(intent: Intent!): IBinder?
Parameters
intent Intent!: The Intent that was used to bind to this service, as given to android.content.Context#bindService. Note that any extras that were included with the Intent at that point will not be seen here.
Return
IBinder? Return an IBinder through which clients can call on to the service.

onGetSupportedVoiceActions

Added in API level 29
open fun onGetSupportedVoiceActions(voiceActions: MutableSet<String!>): MutableSet<String!>

Request to query for what extended voice actions this service supports. This method will be called when the system checks the supported actions of this VoiceInteractionService. Supported actions may be delivered to VoiceInteractionSession later to request a session to perform an action.

Voice actions are defined in support libraries and could vary based on platform context. For example, car related voice actions will be defined in car support libraries.

Parameters
voiceActions MutableSet<String!>: A set of checked voice actions. This value cannot be null.
Return
MutableSet<String!> Returns a subset of checked voice actions. Additional voice actions in the returned set will be ignored. Returns empty set if no actions are supported. This value cannot be null.

onLaunchVoiceAssistFromKeyguard

Added in API level 23
open fun onLaunchVoiceAssistFromKeyguard(): Unit

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 android.R.attr#supportsLaunchVoiceAssistFromKeyguard and the Keyguard is showing.

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

onPrepareToShowSession

Added in API level 34
open fun onPrepareToShowSession(
    args: Bundle,
    flags: Int
): Unit

Notify the interactor when the system prepares to show session. The system is going to bind the session service.

Parameters
args Bundle: The arguments that were supplied to showSession(android.os.Bundle,int). It always includes VoiceInteractionSession#KEY_SHOW_SESSION_ID. This value cannot be null.
flags Int: The show flags originally provided to showSession(android.os.Bundle,int).

onReady

Added in API level 21
open fun onReady(): Unit

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 will not be operational until this point.

onShowSessionFailed

Added in API level 34
open fun onShowSessionFailed(args: Bundle): Unit

Called when the show session failed. E.g. When the system bound the session service failed.

Parameters
args Bundle: Additional info about the show session attempt that failed. For now, includes VoiceInteractionSession#KEY_SHOW_SESSION_ID. This value cannot be null.

onShutdown

Added in API level 21
open fun onShutdown(): Unit

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.

setDisabledShowContext

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

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.

setUiHints

Added in API level 29
fun setUiHints(hints: Bundle): Unit

Provide hints to be reflected in the system UI.

Parameters
hints Bundle: Arguments used to show UI. This value cannot be null.

showSession

Added in API level 23
open fun showSession(
    args: Bundle!,
    flags: Int
): Unit

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

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

Protected methods

dump

Added in API level 21
protected open fun dump(
    fd: FileDescriptor!,
    pw: PrintWriter!,
    args: Array<String!>!
): Unit
Parameters
fd FileDescriptor!: 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 Array<String!>!: additional arguments to the dump request.