accessibility - Accessibility
The accessibility module drives automation through the system accessibility service: find nodes, dispatch gestures, read events, and run global actions. Enable the service in app settings before calling these APIs.
Table of contents
Classes
Interfaces
- Accessibility
- AccessibilityEvent
- AccessibilityWindow
- EnableServiceOptions
- NextEventOptions
- Point
- ToastEvent
Constants
Functions
- back
- click
- clickText
- currentActivity
- currentPackage
- home
- inputText
- lockScreen
- longClick
- nextEvent
- nextEventOrNull
- openNotifications
- openQuickSettings
- performGesture
- performGestures
- performGlobalAction
- press
- scrollBackward
- scrollForward
- select
- sendKeyCodeHeadsethook
- setText
- showLauncherAllApps
- swipe
- takeScreenshot
- togglePowerDialog
- toggleRecents
- toggleSplitScreen
- triggerAccessibilityButton
- triggerAccessibilityShortcut
Constants
accessibility
accessibility:Accessibility=accessibilityInternal
Singleton for the accessibility service API.
Functions
back
back(): boolean
Simulates the Back key.
Returns
boolean
true if the action succeeded.
click
click(x: number, y: number): Promise<boolean>
Taps at screen coordinates. Origin is the top-left; values increase to the right and down (typically up to the device resolution).
Parameters
x: X coordinate.y: Y coordinate.
Returns
Promise<boolean>
clickText
clickText(text: string, index?: number): Promise<boolean>
Taps the given visible text on the screen.
Parameters
text: Text to tap.index: Which matching text occurrence to tap, zero-based (default0).
Returns
Promise<boolean>
currentActivity
currentActivity(): string | null
Returns the activity class name last observed as foreground; usually the current app’s activity.
Returns
string | null
Activity name, or null without permission or data.
currentPackage
currentPackage(clearCache?: boolean): string | null
Returns the package name of the focused or active window. This can be a floating window (if it has focus, its package is returned). Returns null when there is no focused window, no active window, or no accessibility permission.
Parameters
clearCache: Whether to clear cached package info before reading (defaulttrue).
Returns
string | null
home
home(): boolean
Simulates the Home key.
Returns
boolean
true if the action succeeded.
inputText
inputText(text: string, index?: number): Promise<boolean>
Appends text in the focused input field (after existing content).
Parameters
text: Text to type.index: Which input field on the screen, zero-based (default0).
Returns
Promise<boolean>
lockScreen
lockScreen(): boolean
Locks the screen.
Returns
boolean
true on success. Requires Android 9 or above.
longClick
longClick(x: number, y: number): Promise<boolean>
Long-press at the given coordinates.
Parameters
x: X coordinate.y: Y coordinate.
Returns
Promise<boolean>
nextEvent
nextEvent(event: string, options?: NextEventOptions ): Promise<android.view.accessibility.AccessibilityEvent>
Parameters
event: Event type name.options: Optional wait / filter options.
Returns
Promise<android.view.accessibility.AccessibilityEvent>
nextEventOrNull
nextEventOrNull(event: string, options?: NextEventOptions ): Promise<android.view.accessibility.AccessibilityEvent | null>
Like nextEvent, but the promise may resolve to null when no matching event is produced (see NextEventOptions).
Parameters
event: Event type name.options: Optional wait / filter options.
Returns
Promise<android.view.accessibility.AccessibilityEvent | null>
openNotifications
openNotifications(): boolean
Opens the notification shade.
Returns
boolean
true if the action succeeded.
openQuickSettings
openQuickSettings(): boolean
Opens quick settings (notification shade pulled down fully).
Returns
boolean
true if the action succeeded.
performGesture
performGesture(points: Point [], duration: number, delay?: number): Promise<boolean>
Dispatches a gesture along a polyline through points. Many points can approximate a curve.
Parameters
points: Path vertices.duration: Total duration in milliseconds.delay: Delay before the gesture starts, in milliseconds (default0).
Returns
Promise<boolean>
Resolves when the gesture finishes; indicates success.
performGestures
performGestures(gestures: StrokeDescription []): Promise<boolean>
Runs multiple gestures concurrently.
Parameters
gestures: Array of stroke descriptions.
Returns
Promise<boolean>
performGlobalAction
performGlobalAction(action: number): boolean
Performs an Android accessibility global action (see AccessibilityService / GLOBAL_ACTION_* constants).
Parameters
action: Global action id.
Returns
boolean
true if the action succeeded.
press
press(x: number, y: number, duration: number): Promise<boolean>
Holds at (x, y) for duration ms.
Parameters
x: X coordinate.y: Y coordinate.duration: Hold time in milliseconds.
Returns
Promise<boolean>
Resolves when complete; indicates success.
scrollBackward
scrollBackward(index?: number): Promise<boolean>
Scrolls up or left (backward) on a scrollable node.
Parameters
index: Which scrollable container, zero-based.
Returns
Promise<boolean>
scrollForward
scrollForward(index?: number): Promise<boolean>
Scrolls down or right (forward) on a scrollable node.
Parameters
index: Which scrollable container, zero-based.
Returns
Promise<boolean>
select
select(query?: SelectorQuery ): UiSelector`
Builds a UI selector for accessibility queries.
Parameters
query: Optional filter conditions.
Returns
sendKeyCodeHeadsethook
sendKeyCodeHeadsethook(): boolean
Sends KEYCODE_HEADSETHOOK. Requires Android 12 or above.
Returns
boolean
true if the action succeeded.
setText
setText(text: string, index?: number): Promise<boolean>
Sets the text of the target field (replaces content per platform behavior).
Parameters
text: New text.index: Which input field, zero-based (default0).
Returns
Promise<boolean>
showLauncherAllApps
showLauncherAllApps(): boolean
Shows the launcher “all apps” drawer. Requires Android 12 or above.
Returns
boolean
true if the action succeeded.
swipe
swipe(x1: number, y1: number, x2: number, y2: number, duration: number): Promise<boolean>
Straight-line swipe from (x1, y1) to (x2, y2) over duration ms.
Parameters
x1,y1: Start point.x2,y2: End point.duration: Duration in milliseconds.
Returns
Promise<boolean>
Resolves when complete; indicates success.
takeScreenshot
takeScreenshot(displayId?: number): Promise< Image >
Captures the screen. Requires Android 11 or above.
Parameters
displayId: Display id (default0).
Returns
Promise< Image >
togglePowerDialog
togglePowerDialog(): boolean
Shows the power menu.
Returns
boolean
true if the action succeeded.
toggleRecents
toggleRecents(): boolean
Simulates the Recents / overview key.
Returns
boolean
true if the action succeeded.
toggleSplitScreen
toggleSplitScreen(): boolean
Toggles split-screen mode.
Returns
boolean
true on success. Requires Android 7.0 or above.
triggerAccessibilityButton
triggerAccessibilityButton(): boolean
Triggers the on-screen accessibility button. Requires Android 12 or above.
Returns
boolean
true if the action succeeded.
triggerAccessibilityShortcut
triggerAccessibilityShortcut(): boolean
Triggers the accessibility shortcut. Requires Android 12 or above.
Returns
boolean
true if the action succeeded.
