
• Const accessibility: Accessibility = accessibilityInternal
无障碍服务实例
▸ back(): boolean
模拟返回按键
boolean
是否成功。
▸ click(x, y): Promise<boolean>
点击屏幕上指定位置。坐标以屏幕左上角为原点,向右下增加。最大值一般等同于设备分辨率。
名称 | 类型 | 描述 |
|---|---|---|
x | number | X坐标 |
y | number | Y坐标 |
Promise<boolean>
▸ clickText(text, index?): Promise<boolean>
点击屏幕中的文本。
名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
text | string | undefined | 需点击的文本内容 |
index | number | 0 | 点击屏幕中的第几个文本,从0开始 |
Promise<boolean>
是否成功的Promise
▸ currentActivity(): string | null
返回最近一次监测到的正在运行的应用的Activity名称,一般可以认为就是当前正在运行的应用的Activity名称。
string | null
Activity名称。无权限则返回null。
▸ currentPackage(clearCache?): string | null
返回当前获得焦点或活跃的窗口包名,需要注意的是,这包括悬浮窗等情况(也即如果悬浮窗获得焦点,将返回悬浮窗的包名)。没有焦点/活跃窗口或没有无障碍权限时,返回null。
名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
clearCache | boolean | true | 是否清除缓存 |
string | null
▸ home(): boolean
模拟Home键
boolean
是否成功。
▸ inputText(text, index?): Promise<boolean>
输入文本(在原输入框内容后追加输入)。
名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
text | string | undefined | 输入的文本内容 |
index | number | 0 | 输入至屏幕中第几个输入框,从0开始 |
Promise<boolean>
是否成功的Promise
▸ lockScreen(): boolean
锁屏。
boolean
是否成功。需要安卓9或以上。
▸ longClick(x, y): Promise<boolean>
长按屏幕指定位置。
名称 | 类型 | 描述 |
|---|---|---|
x | number | X坐标 |
y | number | Y坐标 |
Promise<boolean>
▸ nextEvent(event, options?): Promise<android.view.accessibility.AccessibilityEvent>
名称 | 类型 |
|---|---|
event | string |
options | NextEventOptions |
Promise<android.view.accessibility.AccessibilityEvent>
▸ nextEventOrNull(event, options?): Promise<android.view.accessibility.AccessibilityEvent | null>
名称 | 类型 |
|---|---|
event | string |
options | NextEventOptions |
Promise<android.view.accessibility.AccessibilityEvent | null>
▸ openNotifications(): boolean
拉出通知栏。
boolean
是否成功。
▸ openQuickSettings(): boolean
显示快速设置(下拉通知栏到底)。
boolean
是否成功。
▸ performGesture(points, duration, delay?): Promise<boolean>
模拟手势。依次滑动多个点的折线路径,可通过大量点来模拟曲线。
名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
points | Point[] | undefined | 路径,由点的数组构成。 |
duration | number | undefined | 滑动时长,单位毫秒。 |
delay | number | 0 | 滑动开始延迟,单位毫秒。 |
Promise<boolean>
返回是否运行成功的Promise。
▸ performGestures(gestures): Promise<boolean>
同时模拟多个手势。
名称 | 类型 | 描述 |
|---|---|---|
gestures | StrokeDescription[] | 手势数组。 |
Promise<boolean>
▸ performGlobalAction(action): boolean
模拟全局按键。
名称 | 类型 | 描述 |
|---|---|---|
action | number | GlobalAction |
boolean
是否成功。
▸ press(x, y, duration): Promise<boolean>
按住屏幕指定位置一段时间。
名称 | 类型 | 描述 |
|---|---|---|
x | number | X坐标 |
y | number | Y坐标 |
duration | number | 按住时长,单位毫秒 |
Promise<boolean>
返回是否运行成功的Promise。运行完成时触发。
▸ scrollBackward(index?): Promise<boolean>
向上或向左滑动
名称 | 类型 | 描述 |
|---|---|---|
index? | number | 滑动第几个可滑动布局。从0开始 |
Promise<boolean>
是否成功的Promise
▸ scrollForward(index?): Promise<boolean>
向下或向右滑动
名称 | 类型 | 描述 |
|---|---|---|
index? | number | 滑动第几个可滑动布局。从0开始 |
Promise<boolean>
是否成功的Promise
▸ select(query?): UiSelector
UI选择。
名称 | 类型 | 描述 |
|---|---|---|
query? | SelectorQuery | 筛选条件 |
Ui选择器
▸ sendKeyCodeHeadsethook(): boolean
模拟回车键。需要安卓12或以上。
boolean
是否成功。
▸ setText(text, index?): Promise<boolean>
设置文本
名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
text | string | undefined | 设置的文本内容 |
index | number | 0 | 输入至屏幕中第几个输入框,从0开始 |
Promise<boolean>
是否成功的Promise
▸ showLauncherAllApps(): boolean
显示已安装的全部应用。需要安卓12或以上。
boolean
是否成功。
▸ swipe(x1, y1, x2, y2, duration): Promise<boolean>
直线滑动。
名称 | 类型 | 描述 |
|---|---|---|
x1 | number | 起点X坐标 |
y1 | number | 起点Y坐标 |
x2 | number | 终点X坐标 |
y2 | number | 终点Y坐标 |
duration | number | 滑动时长,单位毫秒 |
Promise<boolean>
返回是否运行成功的Promise。运行完成时触发。
▸ takeScreenshot(displayId?): Promise<Image>
截屏。需要安卓11或以上。
名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
displayId | number | 0 | 屏幕ID。 |
Promise<Image>
返回截屏图片的Promise。
▸ togglePowerDialog(): boolean
显示电源设置。
boolean
是否成功。
▸ toggleRecents(): boolean
模拟最近任务键
boolean
是否成功。
▸ toggleSplitScreen(): boolean
分屏。
boolean
是否成功。需要安卓7.0或以上。
▸ triggerAccessibilityButton(): boolean
触发辅助功能键。需要安卓12或以上。
boolean
是否成功。
▸ triggerAccessibilityShortcut(): boolean
触发辅助功能快捷键。需要安卓12或以上。
boolean
是否成功。