js-apis-inner-application-accessibilityExtensionContext.md 40.8 KB
Newer Older
E
ester.zhou 已提交
1
# AccessibilityExtensionContext (Accessibility Extension Context)
E
esterzhou 已提交
2

E
ester.zhou 已提交
3
The **AccessibilityExtensionContext** module, inherited from **ExtensionContext**, provides context for **AccessibilityExtensionAbility**.
E
esterzhou 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17

You can use the APIs of this module to configure the concerned information, obtain root information, and inject gestures.

> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs of this module can be used only in the stage model.

## Usage

Before using the **AccessibilityExtensionContext** module, you must define a child class that inherits from **AccessibilityExtensionAbility**.

```ts
E
ester.zhou 已提交
18
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
E
esterzhou 已提交
19
let axContext;
E
ester.zhou 已提交
20
class EntryAbility extends AccessibilityExtensionAbility {
E
esterzhou 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    onConnect(): void {
        console.log('AxExtensionAbility onConnect');
        axContext = this.context;
    }
}
```

## FocusDirection

Enumerates the focus directions.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name      | Description     |
| -------- | ------- |
| up       | Search for the next focusable item above the current item in focus.|
| down     | Search for the next focusable item below the current item in focus.|
| left     | Search for the next focusable item on the left of the current item in focus.|
| right    | Search for the next focusable item on the right of the current item in focus.|
| forward  | Search for the next focusable item before the current item in focus.|
| backward | Search for the next focusable item after the current item in focus.|

## FocusType

Enumerates the focus types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name           | Description         |
| ------------- | ----------- |
| accessibility | Accessibility focus.|
| normal        | Normal focus. |

## Rect

Defines a rectangle.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

E
ester.zhou 已提交
60
| Name    | Type    | Readable  | Writable  | Description       |
E
esterzhou 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
| ------ | ------ | ---- | ---- | --------- |
| left   | number | Yes   | No   | Left boundary of the rectangle.|
| top    | number | Yes   | No   | Top boundary of the rectangle.|
| width  | number | Yes   | No   | Width of the rectangle. |
| height | number | Yes   | No   | Height of the rectangle. |

## WindowType

Enumerates the window types.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name         | Description       |
| ----------- | --------- |
| application | Application window.|
| system      | System window.|

## AccessibilityExtensionContext.setTargetBundleName

setTargetBundleName(targetNames: Array\<string>): Promise\<void>;

Sets the concerned target bundle. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
88
| Name        | Type                 | Mandatory  | Description      |
E
esterzhou 已提交
89 90 91 92 93
| ----------- | ------------------- | ---- | -------- |
| targetNames | Array&lt;string&gt; | Yes   | Name of the target bundle.|

**Return value**

E
ester.zhou 已提交
94 95
| Type                 | Description              |
| ------------------- | ---------------- |
E
esterzhou 已提交
96 97 98 99 100 101 102 103 104 105
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

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

## AccessibilityExtensionContext.setTargetBundleName

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

Sets the concerned target bundle. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
123 124 125
| Name        | Type                       | Mandatory  | Description                                      |
| ----------- | ------------------------- | ---- | ---------------------------------------- |
| targetNames | Array&lt;string&gt;       | Yes   | Name of the target bundle.                                |
E
esterzhou 已提交
126 127 128 129 130 131 132 133
| callback    | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result. If the operation fails, **error** that contains data is returned.|

**Example**

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

## AccessibilityExtensionContext.getFocusElement

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

Obtains the focus element. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
155
| Name                 | Type     | Mandatory  | Description                 |
E
esterzhou 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168
| -------------------- | ------- | ---- | ------------------- |
| isAccessibilityFocus | boolean | No   | Whether the obtained focus element is an accessibility focus. The default value is **false**.|

**Return value**

| Type                                 | Description                    |
| ----------------------------------- | ---------------------- |
| Promise&lt;AccessibilityElement&gt; | Promise used to return the current focus element.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
169 170
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
171 172 173 174 175 176 177 178 179 180 181
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let focusElement;
try {
    axContext.getFocusElement().then((data) => {
        focusElement = data;
        console.log('get focus element success');
    }).catch((err) => {
E
ester.zhou 已提交
182
        console.error('failed to get focus element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
183 184
    });
} catch (exception) {
E
ester.zhou 已提交
185
    console.error('failed to get focus element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198
}
```

## AccessibilityExtensionContext.getFocusElement

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

Obtains the focus element. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
199 200 201
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the current focus element.|
E
esterzhou 已提交
202 203 204 205 206

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
207 208
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
209 210 211 212 213 214 215 216
| 9300003 | Do not have accessibility right for this operation. |

**Example**

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

## AccessibilityExtensionContext.getFocusElement

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

Obtains the focus element. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
239 240 241 242
| Name                 | Type                                      | Mandatory  | Description               |
| -------------------- | ---------------------------------------- | ---- | ----------------- |
| isAccessibilityFocus | boolean                                  | Yes   | Whether the obtained focus element is an accessibility focus.   |
| callback             | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the current focus element.|
E
esterzhou 已提交
243 244 245 246 247 248 249 250

**Example**

```ts
let focusElement;
let isAccessibilityFocus = true;
try {
    axContext.getFocusElement(isAccessibilityFocus, (err, data) => {
E
ester.zhou 已提交
251
    if (err && err.code) {
E
ester.zhou 已提交
252
        console.error('failed to get focus element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
253 254 255 256 257 258
        return;
    }
    focusElement = data;
    console.info('get focus element success');
});
} catch (exception) {
E
ester.zhou 已提交
259
    console.error('failed to get focus element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
260 261 262 263 264 265 266 267 268 269 270 271
}
```
## AccessibilityExtensionContext.getWindowRootElement

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

Obtains the root element of a window. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
272 273
| Name     | Type    | Mandatory  | Description                    |
| -------- | ------ | ---- | ---------------------- |
E
esterzhou 已提交
274 275 276 277 278 279 280 281 282 283 284 285
| windowId | number | No   | Window for which you want to obtain the root element. If this parameter is not specified, it indicates the current active window.|

**Return value**

| Type                                 | Description                    |
| ----------------------------------- | ---------------------- |
| Promise&lt;AccessibilityElement&gt; | Promise used to return the root element.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
286 287
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
288 289 290 291 292 293 294 295 296 297 298
| 9300003 | Do not have accessibility right for this operation. |

**Example**

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

## AccessibilityExtensionContext.getWindowRootElement

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

Obtains the root element of a window. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
316 317 318
| Name     | Type                                      | Mandatory  | Description                |
| -------- | ---------------------------------------- | ---- | ------------------ |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the root element.|
E
esterzhou 已提交
319 320 321 322 323

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
324 325
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
326 327 328 329 330 331 332 333
| 9300003 | Do not have accessibility right for this operation. |

**Example**

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

## AccessibilityExtensionContext.getWindowRootElement

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

Obtains the root element of a window. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
356 357 358 359
| Name     | Type                                      | Mandatory  | Description                    |
| -------- | ---------------------------------------- | ---- | ---------------------- |
| windowId | number                                   | Yes   | Window for which you want to obtain the root element. If this parameter is not specified, it indicates the current active window.|
| callback | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the root element.    |
E
esterzhou 已提交
360 361 362 363 364

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
365 366
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
367 368 369 370 371 372 373 374 375
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let rootElement;
let windowId = 10;
try {
    axContext.getWindowRootElement(windowId, (err, data) => {
E
ester.zhou 已提交
376
    if (err && err.code) {
E
ester.zhou 已提交
377
        console.error('failed to get root element of the window, because ${JSON.stringify(err)}');
E
esterzhou 已提交
378 379 380 381 382 383
        return;
    }
    rootElement = data;
    console.info('get root element of the window success');
});
} catch (exception) {
E
ester.zhou 已提交
384
    console.error('failed to get root element of the window, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397
}
```

## AccessibilityExtensionContext.getWindows

getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;

Obtains the list of windows on a display. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
398 399
| Name      | Type    | Mandatory  | Description                   |
| --------- | ------ | ---- | --------------------- |
E
esterzhou 已提交
400 401 402 403
| displayId | number | No   | ID of the display from which the window information is obtained. If this parameter is not specified, it indicates the default main display.|

**Return value**

E
ester.zhou 已提交
404 405
| Type                                      | Description                    |
| ---------------------------------------- | ---------------------- |
E
esterzhou 已提交
406 407 408 409 410 411
| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise used to return the window list.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
412 413
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
414 415 416 417 418 419 420 421 422 423 424
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let windows;
try {
    axContext.getWindows().then((data) => {
        windows = data;
        console.log('get windows success');
    }).catch((err) => {
E
ester.zhou 已提交
425
        console.error('failed to get windows, because ${JSON.stringify(err)}');
E
esterzhou 已提交
426 427
    });
} catch (exception) {
E
ester.zhou 已提交
428
    console.error('failed to get windows, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
429 430 431 432 433 434 435
}
```

## AccessibilityExtensionContext.getWindows

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

E
ester.zhou 已提交
436
Obtains the list of windows on this display. This API uses an asynchronous callback to return the result.
E
esterzhou 已提交
437 438 439 440 441

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
442 443 444
| Name     | Type                                      | Mandatory  | Description               |
| -------- | ---------------------------------------- | ---- | ----------------- |
| callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | Yes   | Callback used to return the window list.|
E
esterzhou 已提交
445 446 447 448 449

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
450 451
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
452 453 454 455 456 457 458 459
| 9300003 | Do not have accessibility right for this operation. |

**Example**

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

## AccessibilityExtensionContext.getWindows

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

Obtains the list of windows on a display. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
482 483 484 485
| Name      | Type                                      | Mandatory  | Description                   |
| --------- | ---------------------------------------- | ---- | --------------------- |
| displayId | number                                   | Yes   | ID of the display from which the window information is obtained. If this parameter is not specified, it indicates the default main display.|
| callback  | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | Yes   | Callback used to return the window list.    |
E
esterzhou 已提交
486 487 488 489 490

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
491 492
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
493 494 495 496 497 498 499 500 501
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let windows;
let displayId = 10;
try {
    axContext.getWindows(displayId, (err, data) => {
E
ester.zhou 已提交
502
        if (err && err.code) {
E
ester.zhou 已提交
503
            console.error('failed to get windows, because ${JSON.stringify(err)}');
E
esterzhou 已提交
504 505 506 507 508 509
            return;
        }
        windows = data;
        console.info('get windows success');
    });
} catch (exception) {
E
ester.zhou 已提交
510
    console.error('failed to get windows, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523
}
```

## AccessibilityExtensionContext.injectGesture

injectGesture(gesturePath: GesturePath): Promise\<void>;

Inject a gesture. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
524 525 526
| Name        | Type                                      | Mandatory  | Description        |
| ----------- | ---------------------------------------- | ---- | ---------- |
| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes   | Path of the gesture to inject.|
E
esterzhou 已提交
527 528 529

**Return value**

E
ester.zhou 已提交
530 531
| Type                 | Description              |
| ------------------- | ---------------- |
E
esterzhou 已提交
532 533 534 535 536 537
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
538 539
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
540 541 542 543 544
| 9300003 | Do not have accessibility right for this operation. |

**Example**

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

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

Inject a gesture. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
572 573 574 575
| Name        | Type                                      | Mandatory  | Description                 |
| ----------- | ---------------------------------------- | ---- | ------------------- |
| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes   | Path of the gesture to inject.         |
| callback    | AsyncCallback&lt;void&gt;                | Yes   | Callback used to return the result.|
E
esterzhou 已提交
576 577 578 579 580

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
581 582
| ID  | Error Message                                    |
| ------- | ---------------------------------------- |
E
esterzhou 已提交
583 584 585 586 587
| 9300003 | Do not have accessibility right for this operation. |

**Example**

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

Defines the accessibilityelement. Before calling APIs of **AccessibilityElement**, you must call [AccessibilityExtensionContext.getFocusElement()](#accessibilityextensioncontextgetfocuselement) or [AccessibilityExtensionContext.getWindowRootElement()](#accessibilityextensioncontextgetwindowrootelement) to obtain an **AccessibilityElement** instance.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

E
ester.zhou 已提交
613
### attributeNames
E
esterzhou 已提交
614 615 616 617 618 619 620 621 622

attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;

Obtains all attribute names of this element. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Return value**

E
ester.zhou 已提交
623 624
| Type                           | Description                      |
| ----------------------------- | ------------------------ |
E
esterzhou 已提交
625 626 627 628 629 630 631 632 633 634 635
| Promise&lt;Array&lt;T&gt;&gt; | Promise used to return all attribute names of the element.|

**Example**

```ts
let rootElement;
let attributeNames;
rootElement.attributeNames().then((data) => {
    console.log('get attribute names success');
    attributeNames = data;
}).catch((err) => {
E
ester.zhou 已提交
636
    console.log('failed to get attribute names, because ${JSON.stringify(err)}');
E
esterzhou 已提交
637 638
});
```
E
ester.zhou 已提交
639
### attributeNames
E
esterzhou 已提交
640 641 642 643 644 645 646 647 648

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

Obtains all attribute names of this element. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
649 650 651
| Name     | Type                                 | Mandatory  | Description                 |
| -------- | ----------------------------------- | ---- | ------------------- |
| callback | AsyncCallback&lt;Array&lt;T&gt;&gt; | Yes   | Callback used to return all attribute names of the element.|
E
esterzhou 已提交
652 653 654 655 656 657 658 659

**Example**

```ts
let rootElement;
let attributeNames;
rootElement.attributeNames((err, data) => {
    if (err) {
E
ester.zhou 已提交
660
        console.error('failed to get attribute names, because ${JSON.stringify(err)}');
E
esterzhou 已提交
661 662 663 664 665 666
        return;
    }
    attributeNames = data;
    console.info('get attribute names success');
});
```
E
ester.zhou 已提交
667
### attributeValue
E
esterzhou 已提交
668 669 670 671 672 673 674 675 676

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

Obtains the attribute value based on an attribute name. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
677 678 679
| Name          | Type  | Mandatory  | Description      |
| ------------- | ---- | ---- | -------- |
| attributeName | T    | Yes   | Attribute name.|
E
esterzhou 已提交
680 681 682

**Return value**

E
ester.zhou 已提交
683 684
| Type                                      | Description                         |
| ---------------------------------------- | --------------------------- |
E
esterzhou 已提交
685 686 687 688 689 690
| Promise&lt;ElementAttributeValues[T]&gt; | Promise used to return the attribute value.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
691 692
| ID  | Error Message                         |
| ------- | ----------------------------- |
E
esterzhou 已提交
693 694 695 696 697 698 699 700 701 702 703 704 705
| 9300004 | This property does not exist. |

**Example**

```ts
let attributeName = 'name';
let attributeValue;
let rootElement;
try {
    rootElement.attributeValue(attributeName).then((data) => {
        console.log('get attribute value by name success');
        attributeValue = data;
    }).catch((err) => {
E
ester.zhou 已提交
706
        console.error('failed to get attribute value, because ${JSON.stringify(err)}');
E
esterzhou 已提交
707 708
    });
} catch (exception) {
E
ester.zhou 已提交
709
    console.error('failed to get attribute value, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
710 711
}
```
E
ester.zhou 已提交
712
### attributeValue
E
esterzhou 已提交
713 714 715 716 717 718 719 720 721 722

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

Obtains the attribute value based on an attribute name. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
723 724 725 726
| Name          | Type                                      | Mandatory  | Description                    |
| ------------- | ---------------------------------------- | ---- | ---------------------- |
| attributeName | T                                        | Yes   | Attribute name.              |
| callback      | AsyncCallback&lt;ElementAttributeValues[T]&gt; | Yes   | Callback used to return the attribute value.|
E
esterzhou 已提交
727 728 729 730 731

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
732 733
| ID  | Error Message                         |
| ------- | ----------------------------- |
E
esterzhou 已提交
734 735 736 737 738 739 740 741 742 743 744
| 9300004 | This property does not exist. |

**Example**

```ts
let rootElement;
let attributeValue;
let attributeName = 'name';
try {
    rootElement.attributeValue(attributeName, (err, data) => {
        if (err) {
E
ester.zhou 已提交
745
            console.error('failed to get attribute value, because ${JSON.stringify(err)}');
E
esterzhou 已提交
746 747 748 749 750 751
            return;
        }
        attributeValue = data;
        console.info('get attribute value success');
    });
} catch (exception) {
E
ester.zhou 已提交
752
    console.error('failed to get attribute value, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
753 754
}
```
E
ester.zhou 已提交
755
### actionNames
E
esterzhou 已提交
756 757 758 759 760 761 762 763 764

actionNames(): Promise\<Array\<string>>;

Obtains the names of all actions supported by this element. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Return value**

E
ester.zhou 已提交
765 766
| Type                                | Description                        |
| ---------------------------------- | -------------------------- |
E
esterzhou 已提交
767 768 769 770 771 772 773 774 775 776 777
| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the names of all actions supported by the element.|

**Example**

```ts
let rootElement;
let actionNames;
rootElement.actionNames().then((data) => {
    console.log('get action names success');
    actionNames = data;
}).catch((err) => {
E
ester.zhou 已提交
778
    console.error('failed to get action names because ${JSON.stringify(err)}');
E
esterzhou 已提交
779 780
});
```
E
ester.zhou 已提交
781
### actionNames
E
esterzhou 已提交
782 783 784 785 786 787 788 789 790

actionNames(callback: AsyncCallback\<Array\<string>>): void;

Obtains the names of all actions supported by this element. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
791 792 793
| Name     | Type                                      | Mandatory  | Description                   |
| -------- | ---------------------------------------- | ---- | --------------------- |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes   | Callback used to return the names of all actions supported by the element.|
E
esterzhou 已提交
794 795 796 797 798 799 800 801

**Example**

```ts
let rootElement;
let actionNames;
rootElement.actionNames((err, data) => {
    if (err) {
E
ester.zhou 已提交
802
        console.error('failed to get action names, because ${JSON.stringify(err)}');
E
esterzhou 已提交
803 804 805 806 807 808
        return;
    }
    actionNames = data;
    console.info('get action names success');
});
```
E
ester.zhou 已提交
809
### performAction
E
esterzhou 已提交
810 811 812 813 814 815 816 817 818 819 820

performAction(actionName: string, parameters?: object): Promise\<void>;

Performs an action based on the specified action name. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
E
ester.zhou 已提交
821 822
| actionName | string | Yes   | Action name. For details, see [Action](./js-apis-accessibility.md#action).
| parameters | object | No   | Parameters required for performing the target action. Empty by default. Not supported currently.    |
E
esterzhou 已提交
823 824 825

**Return value**

E
ester.zhou 已提交
826 827
| Type                 | Description              |
| ------------------- | ---------------- |
E
esterzhou 已提交
828 829 830 831 832 833
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
834 835
| ID  | Error Message                         |
| ------- | ----------------------------- |
E
esterzhou 已提交
836 837 838 839 840 841 842 843 844 845
| 9300005 | This action is not supported. |

**Example**

```ts
let rootElement;
try {
    rootElement.performAction('action').then((data) => {
        console.info('perform action success');
    }).catch((err) => {
E
ester.zhou 已提交
846
        console.error('failed to perform action, because ${JSON.stringify(err)}');
E
esterzhou 已提交
847 848
    });
} catch (exception) {
E
ester.zhou 已提交
849
    console.error('failed to perform action, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
850 851
}
```
E
ester.zhou 已提交
852
### performAction
E
esterzhou 已提交
853 854 855 856 857 858 859 860 861 862 863

performAction(actionName: string, callback: AsyncCallback\<void>): void;

Performs an action based on the specified action name. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
E
ester.zhou 已提交
864
| actionName | string | Yes   | Action name. For details, see [Action](./js-apis-accessibility.md#action).
E
esterzhou 已提交
865 866 867 868 869 870
| callback | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
871 872
| ID  | Error Message                         |
| ------- | ----------------------------- |
E
esterzhou 已提交
873 874 875 876 877 878 879 880 881
| 9300005 | This action is not supported. |

**Example**

```ts
let rootElement;
try {
    rootElement.performAction('action', (err, data) => {
        if (err) {
E
ester.zhou 已提交
882
            console.error('failed to perform action, because ${JSON.stringify(err)}');
E
esterzhou 已提交
883 884 885 886 887
            return;
        }
        console.info('perform action success');
    });
} catch (exception) {
E
ester.zhou 已提交
888
    console.error('failed to perform action, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
889 890
}
```
E
ester.zhou 已提交
891
### performAction
E
esterzhou 已提交
892 893 894 895 896 897 898 899 900

performAction(actionName: string, parameters: object, callback: AsyncCallback\<void>): void;

Performs an action based on the specified action name. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
901 902 903
| Name       | Type                       | Mandatory  | Description                                      |
| ---------- | ------------------------- | ---- | ---------------------------------------- |
| actionName | string                    | Yes   | Action name. For details, see [Action](./js-apis-accessibility.md#action).|
E
ester.zhou 已提交
904
| parameters | object                    | Yes   | Parameters required for performing the target action. Empty by default. Not supported currently.                 |
E
ester.zhou 已提交
905
| callback   | AsyncCallback&lt;void&gt; | Yes   | Callback used to return the result.                       |
E
esterzhou 已提交
906 907 908 909 910

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

E
ester.zhou 已提交
911 912
| ID  | Error Message                         |
| ------- | ----------------------------- |
E
esterzhou 已提交
913 914 915 916 917 918 919 920 921 922 923 924 925
| 9300005 | This action is not supported. |

**Example**

```ts
let rootElement;
let actionName = 'action';
let parameters = {
    'setText': 'test text'
};
try {
    rootElement.performAction(actionName, parameters, (err, data) => {
        if (err) {
E
ester.zhou 已提交
926
            console.error('failed to perform action, because ${JSON.stringify(err)}');
E
esterzhou 已提交
927 928 929 930 931
            return;
        }
        console.info('perform action success');
    });
} catch (exception) {
E
ester.zhou 已提交
932
    console.error('failed to perform action, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
933 934
}
```
E
ester.zhou 已提交
935
### findElement('content')
E
esterzhou 已提交
936 937 938 939 940 941 942 943 944

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

Queries the element information of the **content** type. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
945 946 947 948
| Name      | Type    | Mandatory  | Description                           |
| --------- | ------ | ---- | ----------------------------- |
| type      | string | Yes   | Information type. The value is fixed at **'content'**.|
| condition | string | Yes   | Search criteria.                     |
E
esterzhou 已提交
949 950 951

**Return value**

E
ester.zhou 已提交
952 953
| Type                                      | Description                           |
| ---------------------------------------- | ----------------------------- |
E
esterzhou 已提交
954 955 956 957 958 959 960 961 962 963 964 965 966 967
| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise used to return the result.|

**Example**

```ts
let rootElement;
let type = 'content';
let condition = 'keyword';
let elements;
try {
    rootElement.findElement(type, condition).then((data) => {
        elements = data;
        console.log('find element success');
    }).catch((err) => {
E
ester.zhou 已提交
968
        console.error('failed to find element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
969 970
    });
} catch (exception) {
E
ester.zhou 已提交
971
    console.error('failed to find element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
972 973
}
```
E
ester.zhou 已提交
974
### findElement('content')
E
esterzhou 已提交
975 976 977 978 979 980 981 982 983

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

Queries the element information of the **content** type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
984 985 986 987 988
| Name      | Type                                      | Mandatory  | Description                          |
| --------- | ---------------------------------------- | ---- | ---------------------------- |
| type      | string                                   | Yes   | Information type. The value is fixed at **'content'**.|
| condition | string                                   | Yes   | Search criteria.                    |
| callback  | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | Yes   | Callback used to return the result.    |
E
esterzhou 已提交
989 990 991 992 993 994 995 996 997 998 999

**Example**

```ts
let rootElement;
let type = 'content';
let condition = 'keyword';
let elements;
try {
    rootElement.findElement(type, condition, (err, data) => {
        if (err) {
E
ester.zhou 已提交
1000
            console.error('failed to find element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
1001 1002 1003 1004 1005 1006
            return;
        }
        elements = data;
        console.info('find element success');
    });
} catch (exception) {
E
ester.zhou 已提交
1007
    console.error('failed to find element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
1008 1009
}
```
E
ester.zhou 已提交
1010
### findElement('focusType')
E
esterzhou 已提交
1011 1012 1013 1014 1015 1016 1017 1018 1019

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

Queries the element information of the **focusType** type. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
1020 1021 1022 1023
| Name      | Type                     | Mandatory  | Description                                |
| --------- | ----------------------- | ---- | ---------------------------------- |
| type      | string                  | Yes   | Information type. The value is fixed at **'focusType'**.|
| condition | [FocusType](#focustype) | Yes   | Enumerates the focus types.                      |
E
esterzhou 已提交
1024 1025 1026

**Return value**

E
ester.zhou 已提交
1027 1028
| Type                                 | Description                            |
| ----------------------------------- | ------------------------------ |
E
esterzhou 已提交
1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
| Promise&lt;AccessibilityElement&gt; | Promise used to return the result.|

**Example**

```ts
let rootElement;
let type = 'focusType';
let condition = 'normal';
let element;
try {
    rootElement.findElement(type, condition).then((data) => {
        element = data;
        console.log('find element success');
    }).catch((err) => {
E
ester.zhou 已提交
1043
        console.error('failed to find element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
1044 1045
    });
} catch (exception) {
E
ester.zhou 已提交
1046
    console.error('failed to find element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
1047 1048
}
```
E
ester.zhou 已提交
1049
### findElement('focusType')
E
esterzhou 已提交
1050 1051 1052 1053 1054 1055 1056 1057 1058

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

Queries the element information of the **focusType** type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
1059 1060 1061 1062 1063
| Name      | Type                                      | Mandatory  | Description                                |
| --------- | ---------------------------------------- | ---- | ---------------------------------- |
| type      | string                                   | Yes   | Information type. The value is fixed at **'focusType'**.|
| condition | [FocusType](#focustype)                  | Yes   | Enumerates the focus types.                      |
| callback  | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the result.         |
E
esterzhou 已提交
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074

**Example**

```ts
let rootElement;
let type = 'focusType';
let condition = 'normal';
let element;
try {
    rootElement.findElement(type, condition, (err, data) => {
        if (err) {
E
ester.zhou 已提交
1075
            console.error('failed to find element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
1076 1077 1078 1079 1080 1081
            return;
        }
        element = data;
        console.info('find element success');
    });
} catch (exception) {
E
ester.zhou 已提交
1082
    console.error('failed to find element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
1083 1084
}
```
E
ester.zhou 已提交
1085
### findElement('focusDirection')
E
esterzhou 已提交
1086 1087 1088 1089 1090 1091 1092 1093 1094

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

Queries the element information of the **focusDirection** type. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
1095 1096 1097 1098
| Name      | Type                               | Mandatory  | Description                                      |
| --------- | --------------------------------- | ---- | ---------------------------------------- |
| type      | string                            | Yes   | Information type. The value is fixed at **'focusDirection'**.|
| condition | [FocusDirection](#focusdirection) | Yes   | Enumerates the focus directions.                          |
E
esterzhou 已提交
1099 1100 1101

**Return value**

E
ester.zhou 已提交
1102 1103
| Type                                 | Description                              |
| ----------------------------------- | -------------------------------- |
E
esterzhou 已提交
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
| Promise&lt;AccessibilityElement&gt; | Promise used to return the result.|

**Example**

```ts
let rootElement;
let type = 'focusDirection';
let condition = 'up';
let element;
try {
    rootElement.findElement(type, condition).then((data) => {
        element = data;
        console.log('find element success');
    }).catch((err) => {
E
ester.zhou 已提交
1118
        console.error('failed to find element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
1119 1120
    });
} catch (exception) {
E
ester.zhou 已提交
1121
    console.error('failed to find element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
1122 1123
}
```
E
ester.zhou 已提交
1124
### findElement('focusDirection')
E
esterzhou 已提交
1125 1126 1127 1128 1129 1130 1131 1132 1133

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

Queries the element information of the **focusDirection** type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

E
ester.zhou 已提交
1134 1135 1136 1137 1138
| Name      | Type                                      | Mandatory  | Description                                      |
| --------- | ---------------------------------------- | ---- | ---------------------------------------- |
| type      | string                                   | Yes   | Information type. The value is fixed at **'focusDirection'**.|
| condition | [FocusDirection](#focusdirection)        | Yes   | Direction of the next focus element.                          |
| callback  | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the result.             |
E
esterzhou 已提交
1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149

**Example**

```ts
let rootElement;
let type = 'focusDirection';
let condition = 'up';
let elements;
try {
    rootElement.findElement(type, condition, (err, data) => {
        if (err) {
E
ester.zhou 已提交
1150
            console.error('failed to find element, because ${JSON.stringify(err)}');
E
esterzhou 已提交
1151 1152 1153 1154 1155 1156
            return;
        }
        elements = data;
        console.info('find element success');
    });
} catch (exception) {
E
ester.zhou 已提交
1157
    console.error('failed to find element, because ${JSON.stringify(exception)}');
E
esterzhou 已提交
1158 1159
}
```