# VoiceInteractor

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/app/VoiceInteractor#nestedclasses)\|[Methods](https://developer.android.com/reference/android/app/VoiceInteractor#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/app/VoiceInteractor#inhmethods)  

# VoiceInteractor

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/app/VoiceInteractor "View this page in Kotlin")\|Java

`
public

final

class
VoiceInteractor
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-----------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.app.VoiceInteractor |

<br />

*** ** * ** ***

Interface for an[Activity](https://developer.android.com/reference/android/app/Activity)to interact with the user through voice. Use[Activity.getVoiceInteractor](https://developer.android.com/reference/android/app/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(Request)](https://developer.android.com/reference/android/app/VoiceInteractor#submitRequest(android.app.VoiceInteractor.Request)), providing a new instance of a[Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request)subclass describing the type of operation to perform -- currently the possible requests are[ConfirmationRequest](https://developer.android.com/reference/android/app/VoiceInteractor.ConfirmationRequest)and[CommandRequest](https://developer.android.com/reference/android/app/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](https://developer.android.com/reference/android/app/VoiceInteractor.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.

## Summary

|                                                                                                                                 ### Nested classes                                                                                                                                 ||
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` class` | [VoiceInteractor.AbortVoiceRequest](https://developer.android.com/reference/android/app/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.        |
| ` class` | [VoiceInteractor.CommandRequest](https://developer.android.com/reference/android/app/VoiceInteractor.CommandRequest) Execute a vendor-specific command using the trusted system VoiceInteractionService.                                                                 |
| ` class` | [VoiceInteractor.CompleteVoiceRequest](https://developer.android.com/reference/android/app/VoiceInteractor.CompleteVoiceRequest) Reports that the current interaction was successfully completed with voice, so the application can report the final status to the user. |
| ` class` | [VoiceInteractor.ConfirmationRequest](https://developer.android.com/reference/android/app/VoiceInteractor.ConfirmationRequest) Confirms an operation with the user via the trusted system VoiceInteractionService.                                                       |
| ` class` | [VoiceInteractor.PickOptionRequest](https://developer.android.com/reference/android/app/VoiceInteractor.PickOptionRequest) Select a single option from multiple potential options with the user via the trusted system VoiceInteractionService.                          |
| ` class` | [VoiceInteractor.Prompt](https://developer.android.com/reference/android/app/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.                                   |
| ` class` | [VoiceInteractor.Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request) Base class for voice interaction requests that can be submitted to the interactor.                                                                                |

|                                                                                                                                                                                                                                                                                              ### Public methods                                                                                                                                                                                                                                                                                               ||
|-----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[VoiceInteractor.Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request) | ` `[getActiveRequest](https://developer.android.com/reference/android/app/VoiceInteractor#getActiveRequest(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` name) ` Return any currently active request that was submitted with the given name.                                                                                                                                                                                                            |
| ` `[Request[]](https://developer.android.com/reference/android/app/VoiceInteractor.Request)               | ` `[getActiveRequests](https://developer.android.com/reference/android/app/VoiceInteractor#getActiveRequests())`() ` Return all currently active requests.                                                                                                                                                                                                                                                                                                                                         |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                     | ` `[getPackageName](https://developer.android.com/reference/android/app/VoiceInteractor#getPackageName())`() `                                                                                                                                                                                                                                                                                                                                                                                     |
| ` boolean`                                                                                                | ` `[isDestroyed](https://developer.android.com/reference/android/app/VoiceInteractor#isDestroyed())`() `                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`                                                                                                   | ` `[notifyDirectActionsChanged](https://developer.android.com/reference/android/app/VoiceInteractor#notifyDirectActionsChanged())`() ` Notifies the assist framework that the direct actions supported by the app changed.                                                                                                                                                                                                                                                                         |
| ` boolean`                                                                                                | ` `[registerOnDestroyedCallback](https://developer.android.com/reference/android/app/VoiceInteractor#registerOnDestroyedCallback(java.util.concurrent.Executor,%20java.lang.Runnable))`(`[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[Runnable](https://developer.android.com/reference/java/lang/Runnable)` callback) ` Registers a callback to be called when the VoiceInteractor is destroyed.                                                |
| ` boolean`                                                                                                | ` `[submitRequest](https://developer.android.com/reference/android/app/VoiceInteractor#submitRequest(android.app.VoiceInteractor.Request))`(`[VoiceInteractor.Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request)` request) `                                                                                                                                                                                                                                    |
| ` boolean`                                                                                                | ` `[submitRequest](https://developer.android.com/reference/android/app/VoiceInteractor#submitRequest(android.app.VoiceInteractor.Request,%20java.lang.String))`(`[VoiceInteractor.Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request)` request, `[String](https://developer.android.com/reference/java/lang/String)` name) ` Submit a new[Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request)to the voice interaction service. |
| ` boolean[]`                                                                                              | ` `[supportsCommands](https://developer.android.com/reference/android/app/VoiceInteractor#supportsCommands(java.lang.String[]))`(`[String[]](https://developer.android.com/reference/java/lang/String)` commands) ` Queries the supported commands available from the VoiceInteractionService.                                                                                                                                                                                                     |
| ` boolean`                                                                                                | ` `[unregisterOnDestroyedCallback](https://developer.android.com/reference/android/app/VoiceInteractor#unregisterOnDestroyedCallback(java.lang.Runnable))`(`[Runnable](https://developer.android.com/reference/java/lang/Runnable)` callback) ` Unregisters a previously registered onDestroy callback                                                                                                                                                                                             |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public methods

### getActiveRequest

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public VoiceInteractor.Request getActiveRequest (String name)
```

Return any currently active request that was submitted with the given name.

<br />

|                                                                                                                                       Parameters                                                                                                                                        ||
|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `name` | `String`: The name used to submit the request, as per[submitRequest(android.app.VoiceInteractor.Request, java.lang.String)](https://developer.android.com/reference/android/app/VoiceInteractor#submitRequest(android.app.VoiceInteractor.Request,%20java.lang.String)). <br /> |

|                                                                                       Returns                                                                                        ||
|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| [VoiceInteractor.Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request) | Returns the active request with that name, or null if there was none. <br /> |

### getActiveRequests

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Request[] getActiveRequests ()
```

Return all currently active requests.

<br />

|                                             Returns                                              ||
|------------------------------------------------------------------------------------------|--------|
| [Request[]](https://developer.android.com/reference/android/app/VoiceInteractor.Request) | <br /> |

### getPackageName

Added in[API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getPackageName ()
```

<br />

<br />

|                                                                                    Returns                                                                                    ||
|--------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the package name of the service providing the VoiceInteractionService. This value cannot be`null`. <br /> |

### isDestroyed

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isDestroyed ()
```

<br />

<br />

|                                                         Returns                                                         ||
|-----------|--------------------------------------------------------------------------------------------------------------|
| `boolean` | whether the voice interactor is destroyed. You should not interact with a destroyed voice interactor. <br /> |

### notifyDirectActionsChanged

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void notifyDirectActionsChanged ()
```

Notifies the assist framework that the direct actions supported by the app changed.

<br />

### registerOnDestroyedCallback

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean registerOnDestroyedCallback (Executor executor, 
                Runnable callback)
```

Registers a callback to be called when the VoiceInteractor is destroyed.

<br />

|                                                                                                                                                                                                                                                                                                                   Parameters                                                                                                                                                                                                                                                                                                                   ||
|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `executor` | `Executor`: Executor on which to run the callback. This value cannot be`null`. Callback and listener events are dispatched through this[Executor](https://developer.android.com/reference/java/util/concurrent/Executor), providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use[Context.getMainExecutor()](https://developer.android.com/reference/android/content/Context#getMainExecutor()). Otherwise, provide an[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)that dispatches to an appropriate thread. <br /> |
| `callback` | `Runnable`: The callback to run. This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

|                        Returns                         ||
|-----------|---------------------------------------------|
| `boolean` | whether the callback was registered. <br /> |

### submitRequest

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean submitRequest (VoiceInteractor.Request request)
```

<br />

<br />

|                 Parameters                  ||
|-----------|----------------------------------|
| `request` | `VoiceInteractor.Request` <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### submitRequest

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean submitRequest (VoiceInteractor.Request request, 
                String name)
```

Submit a new[Request](https://developer.android.com/reference/android/app/VoiceInteractor.Request)to the voice interaction service. The request must be one of the available subclasses --[ConfirmationRequest](https://developer.android.com/reference/android/app/VoiceInteractor.ConfirmationRequest),[PickOptionRequest](https://developer.android.com/reference/android/app/VoiceInteractor.PickOptionRequest),[CompleteVoiceRequest](https://developer.android.com/reference/android/app/VoiceInteractor.CompleteVoiceRequest),[AbortVoiceRequest](https://developer.android.com/reference/android/app/VoiceInteractor.AbortVoiceRequest), or[CommandRequest](https://developer.android.com/reference/android/app/VoiceInteractor.CommandRequest).

<br />

|                                                                                                                                                                                 Parameters                                                                                                                                                                                 ||
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `request` | `VoiceInteractor.Request`: The desired request to submit. <br />                                                                                                                                                                                                                                                                                                |
| `name`    | `String`: An optional name for this request, or null. This can be used later with[getActiveRequests()](https://developer.android.com/reference/android/app/VoiceInteractor#getActiveRequests())and[getActiveRequest(String)](https://developer.android.com/reference/android/app/VoiceInteractor#getActiveRequest(java.lang.String))to find the request. <br /> |

|                                        Returns                                        ||
|-----------|----------------------------------------------------------------------------|
| `boolean` | Returns true of the request was successfully submitted, else false. <br /> |

### supportsCommands

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean[] supportsCommands (String[] commands)
```

Queries the supported commands available from the VoiceInteractionService. The command is a string that describes the generic operation to be performed. An example might be "org.example.commands.PICK_DATE" to ask the user to pick a date. (Note: This is not an actual working example.)

<br />

|                                Parameters                                ||
|------------|--------------------------------------------------------------|
| `commands` | `String`: The array of commands to query for support. <br /> |

|                                          Returns                                           ||
|-------------|-------------------------------------------------------------------------------|
| `boolean[]` | Array of booleans indicating whether each command is supported or not. <br /> |

### unregisterOnDestroyedCallback

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean unregisterOnDestroyedCallback (Runnable callback)
```

Unregisters a previously registered onDestroy callback

<br />

|                                     Parameters                                     ||
|------------|------------------------------------------------------------------------|
| `callback` | `Runnable`: The callback to remove. This value cannot be`null`. <br /> |

|                         Returns                          ||
|-----------|-----------------------------------------------|
| `boolean` | whether the callback was unregistered. <br /> |