# TouchInteractionController

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

# TouchInteractionController

*** ** * ** ***

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

`
public

final

class
TouchInteractionController
`  
`

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


``


`

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

<br />

*** ** * ** ***

This class allows a service to handle touch exploration and the detection of specialized accessibility gestures. The service receives motion events and can match those motion events against the gestures it supports. The service can also request the framework enter three other states of operation for the duration of this interaction. Upon entering any of these states the framework will take over and the service will not receive motion events until the start of a new interaction. The states are as follows:

- The service can tell the framework that this interaction is touch exploration. The user is trying to explore the screen rather than manipulate it. The framework will then convert the motion events to hover events to support touch exploration.
- The service can tell the framework that this interaction is a dragging interaction where two fingers are used to execute a one-finger gesture such as scrolling the screen. The service must specify which of the two fingers should be passed through to rest of the input pipeline.
- Finally, the service can request that the framework delegate this interaction, meaning pass it through to the rest of the input pipeline as-is.

When[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled, this controller will receive all motion events received by the framework for the specified display when not touch-exploring or delegating. If the service classifies this interaction as touch exploration or delegating the framework will stop sending motion events to the service for the duration of this interaction. If the service classifies this interaction as a dragging interaction the framework will send motion events to the service to allow the service to determine if the interaction still qualifies as dragging or if it has become a delegating interaction. If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is disabled this controller will not receive any motion events because touch interactions are being passed through to the input pipeline unaltered. Note that[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)requires setting[R.attr.canRequestTouchExplorationMode](https://developer.android.com/reference/android/R.attr#canRequestTouchExplorationMode)as well.

<br />

## Summary

|                                                                                                            ### Nested classes                                                                                                             ||
|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [TouchInteractionController.Callback](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController.Callback) callbacks allow services to receive motion events and state change updates. |

|                                                                                                                     ### Constants                                                                                                                     ||
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [STATE_CLEAR](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_CLEAR) The state where the user is not touching the screen.                                                                |
| `int` | [STATE_DELEGATING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_DELEGATING) The user is performing a gesture which is being passed through to the input pipeline as-is.               |
| `int` | [STATE_DRAGGING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_DRAGGING) The state where the user is dragging with two fingers.                                                        |
| `int` | [STATE_TOUCH_EXPLORING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_TOUCH_EXPLORING) The state where the user is explicitly exploring the screen.                                    |
| `int` | [STATE_TOUCH_INTERACTING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_TOUCH_INTERACTING) The state where the user is touching the screen and the service is receiving motion events. |

|                                                                                                                                                                                                                                                                                                             ### Public methods                                                                                                                                                                                                                                                                                                              ||
|------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` int`                                                                       | ` `[getDisplayId](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#getDisplayId())`() `                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` int`                                                                       | ` `[getMaxPointerCount](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#getMaxPointerCount())`() `                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` int`                                                                       | ` `[getState](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#getState())`() `                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` void`                                                                      | ` `[performClick](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#performClick())`() ` If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to perform a click.                                                                                                          |
| ` void`                                                                      | ` `[performLongClickAndStartDrag](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#performLongClickAndStartDrag())`() ` If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to perform a long click.                                                                     |
| ` void`                                                                      | ` `[registerCallback](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#registerCallback(java.util.concurrent.Executor,%20android.accessibilityservice.TouchInteractionController.Callback))`(`[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[TouchInteractionController.Callback](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController.Callback)` callback) ` Adds the specified callback to the list of callbacks. |
| ` void`                                                                      | ` `[requestDelegating](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#requestDelegating())`() ` If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to initiate a delegating interaction.                                                                              |
| ` void`                                                                      | ` `[requestDragging](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#requestDragging(int))`(int pointerId) ` If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to initiate a dragging interaction using the specified pointer.                                        |
| ` void`                                                                      | ` `[requestTouchExploration](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#requestTouchExploration())`() ` If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added for this display this function tells the framework to initiate touch exploration.                                                         |
| ` static `[String](https://developer.android.com/reference/java/lang/String) | ` `[stateToString](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#stateToString(int))`(int state) ` Returns a string representation of the specified state.                                                                                                                                                                                                                                                                                                                                                  |
| ` void`                                                                      | ` `[unregisterAllCallbacks](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#unregisterAllCallbacks())`() ` Removes all callbacks and returns control of touch interactions to the framework.                                                                                                                                                                                                                                                                                                                  |
| ` boolean`                                                                   | ` `[unregisterCallback](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#unregisterCallback(android.accessibilityservice.TouchInteractionController.Callback))`(`[TouchInteractionController.Callback](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController.Callback)` callback) ` Unregisters the specified 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*.                                                                                             | ||

## Constants

### STATE_CLEAR

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

```
public static final int STATE_CLEAR
```

The state where the user is not touching the screen.

<br />

Constant Value: 0 (0x00000000)  

### STATE_DELEGATING

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

```
public static final int STATE_DELEGATING
```

The user is performing a gesture which is being passed through to the input pipeline as-is. The service is not receiving motion events.

<br />

Constant Value: 4 (0x00000004)  

### STATE_DRAGGING

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

```
public static final int STATE_DRAGGING
```

The state where the user is dragging with two fingers. The service is not receiving motion events. The selected finger is being dispatched to the rest of the input pipeline to execute the drag.

<br />

Constant Value: 3 (0x00000003)  

### STATE_TOUCH_EXPLORING

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

```
public static final int STATE_TOUCH_EXPLORING
```

The state where the user is explicitly exploring the screen. The service is not receiving motion events.

<br />

Constant Value: 2 (0x00000002)  

### STATE_TOUCH_INTERACTING

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

```
public static final int STATE_TOUCH_INTERACTING
```

The state where the user is touching the screen and the service is receiving motion events.

<br />

Constant Value: 1 (0x00000001)

## Public methods

### getDisplayId

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

```
public int getDisplayId ()
```

<br />

<br />

|                            Returns                            ||
|-------|--------------------------------------------------------|
| `int` | the display id associated with this controller. <br /> |

### getMaxPointerCount

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

```
public int getMaxPointerCount ()
```

<br />

<br />

|                                   Returns                                   ||
|-------|----------------------------------------------------------------------|
| `int` | the maximum number of pointers that this display will accept. <br /> |

### getState

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

```
public int getState ()
```

<br />

<br />

|                       Returns                       ||
|-------|----------------------------------------------|
| `int` | the current state of this controller. <br /> |

**See also:**

- [STATE_CLEAR](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_CLEAR)
- [STATE_DELEGATING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_DELEGATING)
- [STATE_DRAGGING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_DRAGGING)
- [STATE_TOUCH_EXPLORING](https://developer.android.com/reference/android/accessibilityservice/TouchInteractionController#STATE_TOUCH_EXPLORING)  

### performClick

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

```
public void performClick ()
```

If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to perform a click. The framework will first try to perform[ERROR(/AccessibilityNodeInfo.AccessibilityAction#ACTION_CLICK)](https://developer.android.com/)on the item with accessibility focus. If that fails, the framework will simulate a click using motion events on the last location to have accessibility focus.

<br />

### performLongClickAndStartDrag

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

```
public void performLongClickAndStartDrag ()
```

If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to perform a long click. The framework will simulate a long click using motion events on the last location with accessibility focus and will delegate any movements to the rest of the input pipeline. This allows a user to double-tap and hold to trigger a drag and then execute that drag by moving their finger.

<br />

### registerCallback

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

```
public void registerCallback (Executor executor, 
                TouchInteractionController.Callback callback)
```

Adds the specified callback to the list of callbacks. The callback will run using on the specified[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)', or on the service's main thread if the Executor is`null`.

<br />

|                                                   Parameters                                                   ||
|------------|----------------------------------------------------------------------------------------------------|
| `executor` | `Executor`: the executor for this callback, or`null`to execute on the service's main thread <br /> |
| `callback` | `TouchInteractionController.Callback`: the callback to add, must be non-null <br />                |

### requestDelegating

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

```
public void requestDelegating ()
```

If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to initiate a delegating interaction. Motion events will be passed through as-is to the rest of the input pipeline for the duration of this interaction.

<br />

### requestDragging

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

```
public void requestDragging (int pointerId)
```

If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added, this function tells the framework to initiate a dragging interaction using the specified pointer. The pointer's movements will be passed through to the rest of the input pipeline. Dragging is often used to perform two-finger scrolling.

<br />

|                                                                                      Parameters                                                                                      ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `pointerId` | `int`: the pointer to be passed through to the rest of the input pipeline. If the pointer id is valid but not actually present on the screen it will be ignored. <br /> |

|                                                                           Throws                                                                           ||
|--------------------------------------------------------------------------------------------------------|----------------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the pointer id is outside of the allowed range. |

### requestTouchExploration

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

```
public void requestTouchExploration ()
```

If[AccessibilityServiceInfo.FLAG_REQUEST_TOUCH_EXPLORATION_MODE](https://developer.android.com/reference/android/accessibilityservice/AccessibilityServiceInfo#FLAG_REQUEST_TOUCH_EXPLORATION_MODE)is enabled and at least one callback has been added for this display this function tells the framework to initiate touch exploration. Touch exploration will continue for the duration of this interaction.

<br />

### stateToString

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

```
public static String stateToString (int state)
```

Returns a string representation of the specified state.

<br />

|      Parameters       ||
|---------|--------------|
| `state` | `int` <br /> |

|                                                Returns                                                 ||
|--------------------------------------------------------------------|------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | This value cannot be`null`. <br /> |

### unregisterAllCallbacks

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

```
public void unregisterAllCallbacks ()
```

Removes all callbacks and returns control of touch interactions to the framework.

<br />

### unregisterCallback

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

```
public boolean unregisterCallback (TouchInteractionController.Callback callback)
```

Unregisters the specified callback.

<br />

|                                             Parameters                                             ||
|------------|----------------------------------------------------------------------------------------|
| `callback` | `TouchInteractionController.Callback`: the callback to remove, must be non-null <br /> |

|                               Returns                                ||
|-----------|-----------------------------------------------------------|
| `boolean` | `true`if the callback was removed,`false`otherwise <br /> |