js-apis-inner-application-accessibilityExtensionContext.md 40.4 KB
Newer Older
1
# AccessibilityExtensionContext (辅助功能扩展上下文)
2 3 4

AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境,继承自ExtensionContext。

Z
zaki 已提交
5
辅助功能扩展上下文模块提供辅助功能扩展的上下文环境的能力,包括允许配置辅助应用关注信息类型、查询节点信息、手势注入等。
6 7 8 9

> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10
>
11 12
> 本模块接口仅可在Stage模型下使用。

L
laiguizhong 已提交
13 14
## 使用说明

15
在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例。
16

M
m00512953 已提交
17
```ts
M
mingxihua 已提交
18
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
19
let axContext;
20
class EntryAbility extends AccessibilityExtensionAbility {
L
laiguizhong 已提交
21
    onConnect(): void {
Z
zaki 已提交
22
        console.log('AxExtensionAbility onConnect');
23
        axContext = this.context;
L
laiguizhong 已提交
24 25
    }
}
26 27 28 29 30 31
```

## FocusDirection

表示查询下一焦点元素的方向。

32
**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
33

D
merge  
donglin 已提交
34
| 名称       | 说明      |
H
HelloCrease 已提交
35 36
| -------- | ------- |
| up       | 表示向上查询。 |
37
| down     | 表示向下查询。 |
H
HelloCrease 已提交
38 39 40
| left     | 表示向左查询。 |
| right    | 表示向右查询。 |
| forward  | 表示向前查询。 |
41 42 43 44 45 46
| backward | 表示向后查询。 |

## FocusType

表示查询焦点元素的类型。

47
**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
48

D
merge  
donglin 已提交
49
| 名称            | 说明          |
H
HelloCrease 已提交
50
| ------------- | ----------- |
51
| accessibility | 表示无障碍的焦点类型。 |
H
HelloCrease 已提交
52
| normal        | 表示普通的焦点类型。  |
53 54 55 56 57

## Rect

表示矩形区域。

58
**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
59

60
| 名称     | 类型     | 可读   | 可写   | 说明        |
H
HelloCrease 已提交
61 62 63 64 65
| ------ | ------ | ---- | ---- | --------- |
| left   | number | 是    | 否    | 矩形区域的左边界。 |
| top    | number | 是    | 否    | 矩形区域的上边界。 |
| width  | number | 是    | 否    | 矩形区域的宽度。  |
| height | number | 是    | 否    | 矩形区域的高度。  |
66 67 68 69 70

## WindowType

表示窗口的类型。

71
**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
72

D
merge  
donglin 已提交
73
| 名称          | 说明        |
H
HelloCrease 已提交
74
| ----------- | --------- |
75
| application | 表示应用窗口类型。 |
H
HelloCrease 已提交
76
| system      | 表示系统窗口类型。 |
77 78 79

## AccessibilityExtensionContext.setTargetBundleName

Z
zaki 已提交
80
setTargetBundleName(targetNames: Array\<string>): Promise\<void>;
81

Z
zaki 已提交
82
设置关注的目标包名,使用Promise异步回调。
83 84 85 86 87

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

88
| 参数名         | 类型                  | 必填   | 说明       |
H
HelloCrease 已提交
89 90
| ----------- | ------------------- | ---- | -------- |
| targetNames | Array&lt;string&gt; | 是    | 关注的目标包名。 |
91 92 93

**返回值:**

94 95
| 类型                  | 说明               |
| ------------------- | ---------------- |
Z
zaki 已提交
96
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
97 98 99 100

**示例:**

```ts
Z
zaki 已提交
101
let targetNames = ['com.ohos.xyz'];
102 103 104 105
try {
    axContext.setTargetBundleName(targetNames).then(() => {
        console.info('set target bundle names success');
    }).catch((err) => {
M
mingxihua 已提交
106
        console.error('failed to set target bundle names, because ${JSON.stringify(err)}');
107 108
    });
} catch (exception) {
M
mingxihua 已提交
109
    console.error('failed to set target bundle names, because ${JSON.stringify(exception)}');
110
};
Z
zaki 已提交
111 112 113 114 115 116 117 118 119 120 121 122
```

## AccessibilityExtensionContext.setTargetBundleName

setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>): void;

设置关注的目标包名,使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

123 124 125
| 参数名         | 类型                        | 必填   | 说明                                       |
| ----------- | ------------------------- | ---- | ---------------------------------------- |
| targetNames | Array&lt;string&gt;       | 是    | 关注的目标包名。                                 |
Z
zaki 已提交
126 127 128 129 130 131
| callback    | AsyncCallback&lt;void&gt; | 是    | 回调函数,如果设置关注的目标包名失败,则AsyncCallback中err有数据返回。 |

**示例:**

```ts
let targetNames = ['com.ohos.xyz'];
132 133
try {
    axContext.setTargetBundleName(targetNames, (err, data) => {
134
        if (err && err.code) {
M
mingxihua 已提交
135
            console.error('failed to set target bundle names, because ${JSON.stringify(err)}');
136 137 138 139 140
            return;
        }
        console.info('set target bundle names success');
    });
} catch (exception) {
M
mingxihua 已提交
141
    console.error('failed to set target bundle names, because ${JSON.stringify(exception)}');
142
};
143 144 145 146 147 148
```

## AccessibilityExtensionContext.getFocusElement

getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>;

Z
zaki 已提交
149
获取焦点元素, 使用Promise异步回调。
150 151 152 153 154

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

155
| 参数名                  | 类型      | 必填   | 说明                  |
H
HelloCrease 已提交
156 157
| -------------------- | ------- | ---- | ------------------- |
| isAccessibilityFocus | boolean | 否    | 获取的是否是无障碍焦点元素,默认为否。 |
158 159 160

**返回值:**

H
HelloCrease 已提交
161 162
| 类型                                  | 说明                     |
| ----------------------------------- | ---------------------- |
Z
zaki 已提交
163
| Promise&lt;AccessibilityElement&gt; | Promise对象,返回当前对应的焦点元素。 |
164

165 166 167 168
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

169 170
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
171 172
| 9300003 | Do not have accessibility right for this operation. |

173 174 175
**示例:**

```ts
Z
zaki 已提交
176
let focusElement;
177 178 179 180 181
try {
    axContext.getFocusElement().then((data) => {
        focusElement = data;
        console.log('get focus element success');
    }).catch((err) => {
M
mingxihua 已提交
182
        console.error('failed to get focus element, because ${JSON.stringify(err)}');
183 184
    });
} catch (exception) {
M
mingxihua 已提交
185
    console.error('failed to get focus element, because ${JSON.stringify(exception)}');
186
}
187 188
```

Z
zaki 已提交
189 190 191 192 193 194 195 196 197 198
## AccessibilityExtensionContext.getFocusElement

getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;

获取焦点元素, 使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

199 200 201
| 参数名      | 类型                                       | 必填   | 说明                |
| -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回当前对应的焦点元素。 |
Z
zaki 已提交
202

203 204 205 206
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

207 208
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
209 210
| 9300003 | Do not have accessibility right for this operation. |

Z
zaki 已提交
211 212 213
**示例:**

```ts
214
let focusElement;
215 216
try {
    axContext.getFocusElement((err, data) => {
217
        if (err && err.code) {
M
mingxihua 已提交
218
            console.error('failed to get focus element, because ${JSON.stringify(err)}');
219 220 221 222 223 224
            return;
        }
        focusElement = data;
        console.info('get focus element success');
    });
} catch (exception) {
M
mingxihua 已提交
225
    console.error('failed to get focus element, because ${JSON.stringify(exception)}');
226
}
Z
zaki 已提交
227 228 229 230 231 232 233 234 235 236 237 238
```

## AccessibilityExtensionContext.getFocusElement

getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<AccessibilityElement>): void;

获取焦点元素, 使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

239 240 241 242
| 参数名                  | 类型                                       | 必填   | 说明                |
| -------------------- | ---------------------------------------- | ---- | ----------------- |
| isAccessibilityFocus | boolean                                  | 是    | 获取的是否是无障碍焦点元素。    |
| callback             | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回当前对应的焦点元素。 |
Z
zaki 已提交
243 244 245 246

**示例:**

```ts
247
let focusElement;
248
let isAccessibilityFocus = true;
249 250
try {
    axContext.getFocusElement(isAccessibilityFocus, (err, data) => {
251
    if (err && err.code) {
M
mingxihua 已提交
252
        console.error('failed to get focus element, because ${JSON.stringify(err)}');
Z
zaki 已提交
253 254 255 256 257
        return;
    }
    focusElement = data;
    console.info('get focus element success');
});
258
} catch (exception) {
M
mingxihua 已提交
259
    console.error('failed to get focus element, because ${JSON.stringify(exception)}');
260
}
Z
zaki 已提交
261
```
262 263 264 265
## AccessibilityExtensionContext.getWindowRootElement

getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>;

Z
zaki 已提交
266
获取指定窗口的根节点元素, 使用Promise异步回调。
267 268 269 270 271

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

272 273
| 参数名      | 类型     | 必填   | 说明                     |
| -------- | ------ | ---- | ---------------------- |
Z
zaki 已提交
274
| windowId | number | 否    | 指定窗口的编号,未指定则从当前活跃窗口获取。 |
275 276 277

**返回值:**

Z
zaki 已提交
278 279 280 281
| 类型                                  | 说明                     |
| ----------------------------------- | ---------------------- |
| Promise&lt;AccessibilityElement&gt; | Promise对象,返回指定屏幕的所有窗口。 |

282 283 284 285
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

286 287
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
288 289
| 9300003 | Do not have accessibility right for this operation. |

Z
zaki 已提交
290 291 292 293
**示例:**

```ts
let rootElement;
294 295 296 297 298
try {
    axContext.getWindowRootElement().then((data) => {
        rootElement = data;
        console.log('get root element of the window success');
    }).catch((err) => {
M
mingxihua 已提交
299
        console.error('failed to get root element of the window, because ${JSON.stringify(err)}');
300 301
    });
} catch (exception) {
M
mingxihua 已提交
302
    console.error('failed to get root element of the window, ${JSON.stringify(exception)}');
303
}
Z
zaki 已提交
304 305 306 307 308 309 310 311 312 313 314 315
```

## AccessibilityExtensionContext.getWindowRootElement

getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;

获取指定窗口的根节点元素, 使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

316 317 318
| 参数名      | 类型                                       | 必填   | 说明                 |
| -------- | ---------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回指定窗口的根节点元素。 |
Z
zaki 已提交
319

320 321 322 323
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

324 325
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
326 327
| 9300003 | Do not have accessibility right for this operation. |

Z
zaki 已提交
328 329 330
**示例:**

```ts
331
let rootElement;
332 333
try {
    axContext.getWindowRootElement((err, data) => {
334
    if (err && err.code) {
M
mingxihua 已提交
335
        console.error('failed to get root element of the window, because ${JSON.stringify(err)}');
Z
zaki 已提交
336 337 338 339 340
        return;
    }
    rootElement = data;
    console.info('get root element of the window success');
});
341
} catch (exception) {
M
mingxihua 已提交
342
    console.error('failed to get root element of the window, because ${JSON.stringify(exception)}');
343
}
Z
zaki 已提交
344 345 346 347 348 349 350 351 352 353 354 355
```

## AccessibilityExtensionContext.getWindowRootElement

getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityElement>): void;

获取指定屏幕中的所有窗口, 使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

356 357 358 359
| 参数名      | 类型                                       | 必填   | 说明                     |
| -------- | ---------------------------------------- | ---- | ---------------------- |
| windowId | number                                   | 是    | 指定窗口的编号,未指定则从当前活跃窗口获取。 |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回指定窗口的根节点元素。     |
360

361 362 363 364
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

365 366
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
367 368
| 9300003 | Do not have accessibility right for this operation. |

369 370 371
**示例:**

```ts
372
let rootElement;
373
let windowId = 10;
374 375
try {
    axContext.getWindowRootElement(windowId, (err, data) => {
376
    if (err && err.code) {
M
mingxihua 已提交
377
        console.error('failed to get root element of the window, because ${JSON.stringify(err)}');
Z
zaki 已提交
378 379 380 381 382
        return;
    }
    rootElement = data;
    console.info('get root element of the window success');
});
383
} catch (exception) {
M
mingxihua 已提交
384
    console.error('failed to get root element of the window, because ${JSON.stringify(exception)}');
385
}
386 387 388 389
```

## AccessibilityExtensionContext.getWindows

Z
zaki 已提交
390
getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;
391

Z
zaki 已提交
392
获取指定屏幕中的所有窗口, 使用Promise异步回调。
393 394 395 396 397

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

398 399
| 参数名       | 类型     | 必填   | 说明                    |
| --------- | ------ | ---- | --------------------- |
Z
zaki 已提交
400
| displayId | number | 否    | 指定的屏幕编号,未指定则从默认主屏幕获取。 |
401 402 403

**返回值:**

404 405
| 类型                                       | 说明                     |
| ---------------------------------------- | ---------------------- |
Z
zaki 已提交
406
| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise对象,返回指定屏幕的所有窗口。 |
407

408 409 410 411
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

412 413
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
414 415
| 9300003 | Do not have accessibility right for this operation. |

416 417 418
**示例:**

```ts
Z
zaki 已提交
419
let windows;
420 421 422 423 424
try {
    axContext.getWindows().then((data) => {
        windows = data;
        console.log('get windows success');
    }).catch((err) => {
M
mingxihua 已提交
425
        console.error('failed to get windows, because ${JSON.stringify(err)}');
426 427
    });
} catch (exception) {
M
mingxihua 已提交
428
    console.error('failed to get windows, because ${JSON.stringify(exception)}');
429
}
Z
zaki 已提交
430 431 432 433 434 435 436 437 438 439 440 441
```

## AccessibilityExtensionContext.getWindows

getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void;

获取指定屏幕中的所有窗口, 使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

442 443 444
| 参数名      | 类型                                       | 必填   | 说明                |
| -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是    | 回调函数,返回指定屏幕的所有窗口。 |
Z
zaki 已提交
445

446 447 448 449
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

450 451
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
452 453
| 9300003 | Do not have accessibility right for this operation. |

Z
zaki 已提交
454 455 456 457
**示例:**

```ts
let windows;
458 459
try {
    axContext.getWindows((err, data) => {
460
        if (err && err.code) {
M
mingxihua 已提交
461
            console.error('failed to get windows, because ${JSON.stringify(err)}');
462 463 464 465 466 467
            return;
        }
        windows = data;
        console.info('get windows success');
    });
} catch (exception) {
M
mingxihua 已提交
468
    console.error('failed to get windows, because ${JSON.stringify(exception)}');
469
}
Z
zaki 已提交
470 471 472 473 474 475 476 477 478 479 480 481
```

## AccessibilityExtensionContext.getWindows

getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityElement>>): void;

获取指定屏幕中的所有窗口, 使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

482 483 484 485
| 参数名       | 类型                                       | 必填   | 说明                    |
| --------- | ---------------------------------------- | ---- | --------------------- |
| displayId | number                                   | 是    | 指定的屏幕编号,未指定则从默认主屏幕获取。 |
| callback  | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是    | 回调函数,返回指定屏幕的所有窗口。     |
Z
zaki 已提交
486

487 488 489 490
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

491 492
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
493 494
| 9300003 | Do not have accessibility right for this operation. |

Z
zaki 已提交
495 496 497 498
**示例:**

```ts
let windows;
499 500 501
let displayId = 10;
try {
    axContext.getWindows(displayId, (err, data) => {
502
        if (err && err.code) {
M
mingxihua 已提交
503
            console.error('failed to get windows, because ${JSON.stringify(err)}');
504 505 506 507 508 509
            return;
        }
        windows = data;
        console.info('get windows success');
    });
} catch (exception) {
M
mingxihua 已提交
510
    console.error('failed to get windows, because ${JSON.stringify(exception)}');
511
}
512 513
```

L
laiguizhong 已提交
514
## AccessibilityExtensionContext.injectGesture
515

Z
zaki 已提交
516 517 518 519 520 521 522 523
injectGesture(gesturePath: GesturePath): Promise\<void>;

注入手势,使用Promise异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

524 525 526
| 参数名         | 类型                                       | 必填   | 说明         |
| ----------- | ---------------------------------------- | ---- | ---------- |
| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是    | 表示手势的路径信息。 |
Z
zaki 已提交
527 528 529

**返回值:**

530 531
| 类型                  | 说明               |
| ------------------- | ---------------- |
Z
zaki 已提交
532 533
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |

534 535 536 537
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

538 539
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
540 541
| 9300003 | Do not have accessibility right for this operation. |

Z
zaki 已提交
542 543 544
**示例:**

```ts
M
mingxihua 已提交
545
import GesturePath from '@ohos.accessibility.GesturePath';
546 547
import GesturePoint from '@ohos.accessibility.GesturePoint';
let gesturePath = new GesturePath.GesturePath(100);
548 549
try {
    for (let i = 0; i < 10; i++) {
550
        let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
551 552 553 554 555
        gesturePath.points.push(gesturePoint);
    }
    axContext.injectGesture(gesturePath).then(() => {
        console.info('inject gesture success');
    }).catch((err) => {
M
mingxihua 已提交
556
        console.error('failed to inject gesture, because ${JSON.stringify(err)}');
557 558
    });
} catch (exception) {
M
mingxihua 已提交
559
    console.error('failed to inject gesture, because ${JSON.stringify(exception)}');
Z
zaki 已提交
560 561 562 563
}
```
## AccessibilityExtensionContext.injectGesture

564
injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
565

Z
zaki 已提交
566
注入手势,使用callback异步回调。
567 568 569 570 571

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

572 573 574 575
| 参数名         | 类型                                       | 必填   | 说明                  |
| ----------- | ---------------------------------------- | ---- | ------------------- |
| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是    | 表示手势的路径信息。          |
| callback    | AsyncCallback&lt;void&gt;                | 是    | 回调函数,表示注入手势执行结果的回调。 |
576

577 578 579 580
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

581 582
| 错误码ID   | 错误信息                                     |
| ------- | ---------------------------------------- |
583 584
| 9300003 | Do not have accessibility right for this operation. |

585 586 587
**示例:**

```ts
M
mingxihua 已提交
588
import GesturePath from '@ohos.accessibility.GesturePath';
589 590
import GesturePoint from '@ohos.accessibility.GesturePoint';
let gesturePath = new GesturePath.GesturePath(100);
591 592
try {
    for (let i = 0; i < 10; i++) {
593
        let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
594
        gesturePath.points.push(gesturePoint);
Z
zaki 已提交
595
    }
596
    axContext.injectGesture(gesturePath, (err, data) => {
597
        if (err && err.code) {
M
mingxihua 已提交
598
            console.error('failed to inject gesture, because ${JSON.stringify(err)}');
599 600 601 602 603
            return;
        }
        console.info('inject gesture success');
    });
} catch (exception) {
M
mingxihua 已提交
604
    console.error('failed to inject gesture, because ${JSON.stringify(exception)}');
605
}
606
```
607
## AccessibilityElement<sup>9+</sup>
Z
zaki 已提交
608

609
无障碍节点元素, 在调用AccessibilityElement的方法前,需要先通过[AccessibilityExtensionContext.getFocusElement()](#accessibilityextensioncontextgetfocuselement)或者[AccessibilityExtensionContext.getWindowRootElement()](#accessibilityextensioncontextgetwindowrootelement)获取AccessibilityElement实例。
Z
zaki 已提交
610 611 612 613

**系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Core

## attributeNames
Z
zaki 已提交
614

615
attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;
Z
zaki 已提交
616

Z
zaki 已提交
617
获取节点元素的所有属性名称,使用Promise异步回调。
Z
zaki 已提交
618 619 620 621 622

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**返回值:**

623 624
| 类型                            | 说明                       |
| ----------------------------- | ------------------------ |
Z
zaki 已提交
625
| Promise&lt;Array&lt;T&gt;&gt; | Promise对象,返回节点元素的所有属性名称。 |
Z
zaki 已提交
626 627 628 629

**示例:**

```ts
630
let rootElement;
Z
zaki 已提交
631
let attributeNames;
632 633 634 635
rootElement.attributeNames().then((data) => {
    console.log('get attribute names success');
    attributeNames = data;
}).catch((err) => {
M
mingxihua 已提交
636
    console.log('failed to get attribute names, because ${JSON.stringify(err)}');
637
});
Z
zaki 已提交
638
```
Z
zaki 已提交
639 640 641 642 643 644 645 646 647 648
## attributeNames

attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\<Array\<T>>): void;

获取节点元素的所有属性名称,使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

649 650 651
| 参数名      | 类型                                  | 必填   | 说明                  |
| -------- | ----------------------------------- | ---- | ------------------- |
| callback | AsyncCallback&lt;Array&lt;T&gt;&gt; | 是    | 回调函数,返回节点元素的所有属性名称。 |
Z
zaki 已提交
652 653

**示例:**
Z
zaki 已提交
654

Z
zaki 已提交
655
```ts
656
let rootElement;
Z
zaki 已提交
657
let attributeNames;
658 659
rootElement.attributeNames((err, data) => {
    if (err) {
M
mingxihua 已提交
660
        console.error('failed to get attribute names, because ${JSON.stringify(err)}');
661 662 663 664 665
        return;
    }
    attributeNames = data;
    console.info('get attribute names success');
});
Z
zaki 已提交
666
```
Z
zaki 已提交
667 668 669 670
## AccessibilityElement.attributeValue

attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promise\<ElementAttributeValues[T]>;

Z
zaki 已提交
671
根据属性名称获取属性值,使用Promise异步回调。
Z
zaki 已提交
672 673 674 675 676

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

677 678 679
| 参数名           | 类型   | 必填   | 说明       |
| ------------- | ---- | ---- | -------- |
| attributeName | T    | 是    | 表示属性的名称。 |
Z
zaki 已提交
680 681 682

**返回值:**

683 684
| 类型                                       | 说明                          |
| ---------------------------------------- | --------------------------- |
Z
zaki 已提交
685
| Promise&lt;ElementAttributeValues[T]&gt; | Promise对象,返回根据节点属性名称获取的属性值。 |
Z
zaki 已提交
686

687 688 689 690
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

691 692
| 错误码ID   | 错误信息                          |
| ------- | ----------------------------- |
693 694
| 9300004 | This property does not exist. |

Z
zaki 已提交
695 696 697
**示例:**

```ts
698
let attributeName = 'name';
699 700
let attributeValue;
let rootElement;
Z
zaki 已提交
701
try {
702
    rootElement.attributeValue(attributeName).then((data) => {
Z
zaki 已提交
703
        console.log('get attribute value by name success');
704
        attributeValue = data;
Z
zaki 已提交
705
    }).catch((err) => {
M
mingxihua 已提交
706
        console.error('failed to get attribute value, because ${JSON.stringify(err)}');
Z
zaki 已提交
707
    });
708
} catch (exception) {
M
mingxihua 已提交
709
    console.error('failed to get attribute value, because ${JSON.stringify(exception)}');
Z
zaki 已提交
710 711
}
```
Z
zaki 已提交
712 713 714 715 716 717 718 719 720 721 722
## AccessibilityElement.attributeValue

attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T, 
    callback: AsyncCallback\<ElementAttributeValues[T]>): void;

根据属性名称获取属性值,使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

723 724 725 726
| 参数名           | 类型                                       | 必填   | 说明                     |
| ------------- | ---------------------------------------- | ---- | ---------------------- |
| attributeName | T                                        | 是    | 表示属性的名称。               |
| callback      | AsyncCallback&lt;ElementAttributeValues[T]&gt; | 是    | 回调函数,返回根据节点属性名称获取的属性值。 |
Z
zaki 已提交
727

728 729 730 731
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

732 733
| 错误码ID   | 错误信息                          |
| ------- | ----------------------------- |
734 735
| 9300004 | This property does not exist. |

Z
zaki 已提交
736
**示例:**
Z
zaki 已提交
737

Z
zaki 已提交
738
```ts
739
let rootElement;
Z
zaki 已提交
740
let attributeValue;
741
let attributeName = 'name';
Z
zaki 已提交
742
try {
743
    rootElement.attributeValue(attributeName, (err, data) => {
Z
zaki 已提交
744
        if (err) {
M
mingxihua 已提交
745
            console.error('failed to get attribute value, because ${JSON.stringify(err)}');
Z
zaki 已提交
746 747 748 749 750
            return;
        }
        attributeValue = data;
        console.info('get attribute value success');
    });
751
} catch (exception) {
M
mingxihua 已提交
752
    console.error('failed to get attribute value, because ${JSON.stringify(exception)}');
Z
zaki 已提交
753 754 755
}
```
## actionNames
Z
zaki 已提交
756

757
actionNames(): Promise\<Array\<string>>;
Z
zaki 已提交
758

Z
zaki 已提交
759
获取节点元素支持的所有操作名称,使用Promise异步回调。
Z
zaki 已提交
760 761 762 763 764

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**返回值:**

765 766
| 类型                                 | 说明                         |
| ---------------------------------- | -------------------------- |
Z
zaki 已提交
767
| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回节点元素支持的所有操作名称。 |
Z
zaki 已提交
768 769 770 771

**示例:**

```ts
772
let rootElement;
Z
zaki 已提交
773
let actionNames;
774 775 776 777
rootElement.actionNames().then((data) => {
    console.log('get action names success');
    actionNames = data;
}).catch((err) => {
M
mingxihua 已提交
778
    console.error('failed to get action names because ${JSON.stringify(err)}');
779
});
Z
zaki 已提交
780
```
Z
zaki 已提交
781
## actionNames
Z
zaki 已提交
782

Z
zaki 已提交
783 784 785 786 787 788 789 790
actionNames(callback: AsyncCallback\<Array\<string>>): void;

获取节点元素支持的所有操作名称,使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

791 792 793
| 参数名      | 类型                                       | 必填   | 说明                    |
| -------- | ---------------------------------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 回调函数,返回节点元素支持的所有操作名称。 |
Z
zaki 已提交
794 795 796 797

**示例:**

```ts
798
let rootElement;
Z
zaki 已提交
799
let actionNames;
800 801
rootElement.actionNames((err, data) => {
    if (err) {
M
mingxihua 已提交
802
        console.error('failed to get action names, because ${JSON.stringify(err)}');
803 804 805 806 807
        return;
    }
    actionNames = data;
    console.info('get action names success');
});
Z
zaki 已提交
808 809
```
## performAction
Z
zaki 已提交
810

Z
zaki 已提交
811
performAction(actionName: string, parameters?: object): Promise\<void>;
Z
zaki 已提交
812

Z
zaki 已提交
813
根据操作名称执行某个操作,使用Promise异步回调。
Z
zaki 已提交
814 815 816 817 818

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

819
| 参数名         | 类型                                     | 必填   | 说明             |
Z
zaki 已提交
820
| ----------- | ---------------------------------------- | ---- | -------------- |
821
| actionName | string | 是    | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)
822
| parameters | object | 否    | 表示执行操作时所需要的参数;当前版本暂不支持。     |
Z
zaki 已提交
823 824 825

**返回值:**

826 827
| 类型                  | 说明               |
| ------------------- | ---------------- |
Z
zaki 已提交
828
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
Z
zaki 已提交
829

830 831 832 833
**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

834 835
| 错误码ID   | 错误信息                          |
| ------- | ----------------------------- |
836 837
| 9300005 | This action is not supported. |

Z
zaki 已提交
838 839 840
**示例:**

```ts
841
let rootElement;
Z
zaki 已提交
842
try {
843
    rootElement.performAction('action').then((data) => {
Z
zaki 已提交
844
        console.info('perform action success');
Z
zaki 已提交
845
    }).catch((err) => {
M
mingxihua 已提交
846
        console.error('failed to perform action, because ${JSON.stringify(err)}');
Z
zaki 已提交
847
    });
848
} catch (exception) {
M
mingxihua 已提交
849
    console.error('failed to perform action, because ${JSON.stringify(exception)}');
Z
zaki 已提交
850 851
}
```
Z
zaki 已提交
852 853
## performAction

Z
zaki 已提交
854
performAction(actionName: string, callback: AsyncCallback\<void>): void;
Z
zaki 已提交
855 856 857 858 859 860

根据操作名称执行某个操作,使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**
Z
zaki 已提交
861

862
| 参数名         | 类型                                     | 必填   | 说明             |
Z
zaki 已提交
863
| ----------- | ---------------------------------------- | ---- | -------------- |
864
| actionName | string | 是    | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)
Z
zaki 已提交
865
| callback | AsyncCallback&lt;void&gt; | 是    | 回调函数,表示执行指定操作的回调。|
866 867 868 869 870

**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

871 872
| 错误码ID   | 错误信息                          |
| ------- | ----------------------------- |
873
| 9300005 | This action is not supported. |
Z
zaki 已提交
874 875 876 877

**示例:**

```ts
878
let rootElement;
Z
zaki 已提交
879
try {
880
    rootElement.performAction('action', (err, data) => {
Z
zaki 已提交
881
        if (err) {
M
mingxihua 已提交
882
            console.error('failed to perform action, because ${JSON.stringify(err)}');
Z
zaki 已提交
883 884 885 886
            return;
        }
        console.info('perform action success');
    });
887
} catch (exception) {
M
mingxihua 已提交
888
    console.error('failed to perform action, because ${JSON.stringify(exception)}');
Z
zaki 已提交
889 890 891 892
}
```
## performAction

Z
zaki 已提交
893
performAction(actionName: string, parameters: object, callback: AsyncCallback\<void>): void;
Z
zaki 已提交
894 895 896 897 898 899 900

根据操作名称执行某个操作,使用callback异步回调。

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

901 902 903 904 905
| 参数名        | 类型                        | 必填   | 说明                                       |
| ---------- | ------------------------- | ---- | ---------------------------------------- |
| actionName | string                    | 是    | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。 |
| parameters | object                    | 是    | 表示执行操作时所需要的参数;当前版本暂不支持。                  |
| callback   | AsyncCallback&lt;void&gt; | 是    | 回调函数,表示执行指定操作的回调。                        |
906 907 908 909 910

**错误码:**

以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)

911 912
| 错误码ID   | 错误信息                          |
| ------- | ----------------------------- |
913
| 9300005 | This action is not supported. |
Z
zaki 已提交
914 915 916 917

**示例:**

```ts
918
let rootElement;
Z
zaki 已提交
919 920 921 922 923
let actionName = 'action';
let parameters = {
    'setText': 'test text'
};
try {
924
    rootElement.performAction(actionName, parameters, (err, data) => {
Z
zaki 已提交
925
        if (err) {
M
mingxihua 已提交
926
            console.error('failed to perform action, because ${JSON.stringify(err)}');
Z
zaki 已提交
927 928 929 930
            return;
        }
        console.info('perform action success');
    });
931
} catch (exception) {
M
mingxihua 已提交
932
    console.error('failed to perform action, because ${JSON.stringify(exception)}');
Z
zaki 已提交
933 934 935
}
```
## findElement('content')
Z
zaki 已提交
936

937
findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>;
Z
zaki 已提交
938

939
根据节点内容查询所有节点元素,使用Promise异步回调。
Z
zaki 已提交
940 941 942 943 944

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

945 946 947 948
| 参数名       | 类型     | 必填   | 说明                            |
| --------- | ------ | ---- | ----------------------------- |
| type      | string | 是    | 固定为'content', 表示查找的类型为节点元素内容。 |
| condition | string | 是    | 表示查找的条件。                      |
Z
zaki 已提交
949 950 951

**返回值:**

952 953
| 类型                                       | 说明                            |
| ---------------------------------------- | ----------------------------- |
Z
zaki 已提交
954 955 956 957 958
| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise对象,返回满足指定查询关键字的所有节点元素。 |

**示例:**

```ts
959
let rootElement;
Z
zaki 已提交
960 961 962 963
let type = 'content';
let condition = 'keyword';
let elements;
try {
964
    rootElement.findElement(type, condition).then((data) => {
Z
zaki 已提交
965 966 967
        elements = data;
        console.log('find element success');
    }).catch((err) => {
M
mingxihua 已提交
968
        console.error('failed to find element, because ${JSON.stringify(err)}');
Z
zaki 已提交
969
    });
970
} catch (exception) {
M
mingxihua 已提交
971
    console.error('failed to find element, because ${JSON.stringify(exception)}');
Z
zaki 已提交
972 973 974 975 976 977 978
}
```
## findElement('content')

findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<AccessibilityElement>>): void;

根据节点内容查询所有节点元素。
Z
zaki 已提交
979 980 981 982 983

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

984 985 986 987 988
| 参数名       | 类型                                       | 必填   | 说明                           |
| --------- | ---------------------------------------- | ---- | ---------------------------- |
| type      | string                                   | 是    | 固定为'content',表示查找的类型为节点元素内容。 |
| condition | string                                   | 是    | 表示查找的条件。                     |
| callback  | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是    | 回调函数,返回满足指定查询关键字的所有节点元素。     |
Z
zaki 已提交
989 990 991 992

**示例:**

```ts
993
let rootElement;
Z
zaki 已提交
994 995 996 997
let type = 'content';
let condition = 'keyword';
let elements;
try {
998
    rootElement.findElement(type, condition, (err, data) => {
Z
zaki 已提交
999
        if (err) {
M
mingxihua 已提交
1000
            console.error('failed to find element, because ${JSON.stringify(err)}');
Z
zaki 已提交
1001 1002 1003 1004 1005
            return;
        }
        elements = data;
        console.info('find element success');
    });
1006
} catch (exception) {
M
mingxihua 已提交
1007
    console.error('failed to find element, because ${JSON.stringify(exception)}');
Z
zaki 已提交
1008 1009 1010 1011 1012 1013
}
```
## findElement('focusType')

findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>;

1014
根据焦点元素类型查询节点元素,使用Promise异步回调。
Z
zaki 已提交
1015 1016 1017 1018 1019

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

1020 1021 1022 1023
| 参数名       | 类型                      | 必填   | 说明                                 |
| --------- | ----------------------- | ---- | ---------------------------------- |
| type      | string                  | 是    | 固定为'focusType', 表示查询的类型为节点的焦点元素类型。 |
| condition | [FocusType](#focustype) | 是    | 表示查询焦点元素的类型。                       |
Z
zaki 已提交
1024 1025 1026

**返回值:**

1027 1028
| 类型                                  | 说明                             |
| ----------------------------------- | ------------------------------ |
Z
zaki 已提交
1029
| Promise&lt;AccessibilityElement&gt; | Promise对象,返回满足指定查询焦点元素类型的节点元素。 |
Z
zaki 已提交
1030 1031 1032 1033

**示例:**

```ts
1034
let rootElement;
Z
zaki 已提交
1035 1036
let type = 'focusType';
let condition = 'normal';
1037
let element;
Z
zaki 已提交
1038
try {
1039 1040
    rootElement.findElement(type, condition).then((data) => {
        element = data;
Z
zaki 已提交
1041
        console.log('find element success');
Z
zaki 已提交
1042
    }).catch((err) => {
M
mingxihua 已提交
1043
        console.error('failed to find element, because ${JSON.stringify(err)}');
Z
zaki 已提交
1044
    });
1045
} catch (exception) {
M
mingxihua 已提交
1046
    console.error('failed to find element, because ${JSON.stringify(exception)}');
Z
zaki 已提交
1047 1048 1049 1050 1051 1052
}
```
## findElement('focusType')

findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void;

1053
根据焦点元素类型查询节点元素,使用callback异步回调。
Z
zaki 已提交
1054 1055 1056 1057 1058

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

1059 1060 1061 1062 1063
| 参数名       | 类型                                       | 必填   | 说明                                 |
| --------- | ---------------------------------------- | ---- | ---------------------------------- |
| type      | string                                   | 是    | 固定为'focusType', 表示查询的类型为节点的焦点元素类型。 |
| condition | [FocusType](#focustype)                  | 是    | 表示查询焦点元素的类型。                       |
| callback  | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回满足指定查询焦点元素类型的节点元素。          |
Z
zaki 已提交
1064 1065 1066 1067

**示例:**

```ts
1068
let rootElement;
Z
zaki 已提交
1069 1070
let type = 'focusType';
let condition = 'normal';
1071
let element;
Z
zaki 已提交
1072
try {
1073
    rootElement.findElement(type, condition, (err, data) => {
Z
zaki 已提交
1074
        if (err) {
M
mingxihua 已提交
1075
            console.error('failed to find element, because ${JSON.stringify(err)}');
Z
zaki 已提交
1076 1077
            return;
        }
1078
        element = data;
Z
zaki 已提交
1079 1080
        console.info('find element success');
    });
1081
} catch (exception) {
M
mingxihua 已提交
1082
    console.error('failed to find element, because ${JSON.stringify(exception)}');
Z
zaki 已提交
1083 1084 1085 1086 1087 1088
}
```
## findElement('focusDirection')

findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>;

1089
根据下一焦点元素方向查询节点元素,使用Promise异步回调。
Z
zaki 已提交
1090 1091 1092 1093 1094

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

1095 1096 1097 1098
| 参数名       | 类型                                | 必填   | 说明                                       |
| --------- | --------------------------------- | ---- | ---------------------------------------- |
| type      | string                            | 是    | 固定为'focusDirection', 表示查询的类型为节点的下一焦点元素方向。 |
| condition | [FocusDirection](#focusdirection) | 是    | 表示查询下一焦点元素的方向。                           |
Z
zaki 已提交
1099 1100 1101

**返回值:**

1102 1103
| 类型                                  | 说明                               |
| ----------------------------------- | -------------------------------- |
Z
zaki 已提交
1104 1105 1106 1107 1108
| Promise&lt;AccessibilityElement&gt; | Promise对象,返回满足指定查询下一焦点元素方向的节点元素。 |

**示例:**

```ts
1109
let rootElement;
Z
zaki 已提交
1110 1111
let type = 'focusDirection';
let condition = 'up';
1112
let element;
Z
zaki 已提交
1113
try {
1114 1115
    rootElement.findElement(type, condition).then((data) => {
        element = data;
Z
zaki 已提交
1116 1117
        console.log('find element success');
    }).catch((err) => {
M
mingxihua 已提交
1118
        console.error('failed to find element, because ${JSON.stringify(err)}');
Z
zaki 已提交
1119
    });
1120
} catch (exception) {
M
mingxihua 已提交
1121
    console.error('failed to find element, because ${JSON.stringify(exception)}');
Z
zaki 已提交
1122 1123 1124 1125 1126 1127
}
```
## findElement('focusDirection')

findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void;

1128
根据下一焦点元素方向查询所有节点元素,使用callback异步回调。
Z
zaki 已提交
1129 1130 1131 1132 1133

**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core

**参数:**

1134 1135 1136 1137 1138
| 参数名       | 类型                                       | 必填   | 说明                                       |
| --------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type      | string                                   | 是    | 固定为'focusDirection', 表示查询的类型为节点的下一焦点元素方向。 |
| condition | [FocusDirection](#focusdirection)        | 是    | 表示下一查询焦点元素的方向。                           |
| callback  | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回满足指定查询下一焦点元素方向的节点元素。              |
Z
zaki 已提交
1139 1140 1141 1142

**示例:**

```ts
1143
let rootElement;
Z
zaki 已提交
1144 1145 1146 1147
let type = 'focusDirection';
let condition = 'up';
let elements;
try {
1148
    rootElement.findElement(type, condition, (err, data) => {
Z
zaki 已提交
1149
        if (err) {
M
mingxihua 已提交
1150
            console.error('failed to find element, because ${JSON.stringify(err)}');
Z
zaki 已提交
1151 1152 1153 1154
            return;
        }
        elements = data;
        console.info('find element success');
Z
zaki 已提交
1155
    });
1156
} catch (exception) {
M
mingxihua 已提交
1157
    console.error('failed to find element, because ${JSON.stringify(exception)}');
Z
zaki 已提交
1158 1159
}
```