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