js-apis-inner-application-accessibilityExtensionContext.md 38.8 KB
Newer Older
E
ester.zhou 已提交
1
# AccessibilityExtensionContext (Accessibility Extension Context)
E
esterzhou 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

The **AccessibilityExtensionContext** module, inherited from **ExtensionContext**, provides context for **Accessibility Extension** abilities.

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 60 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    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

| Name    | Type  | Readable  | Writable  | Description       |
| ------ | ------ | ---- | ---- | --------- |
| 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**

| Name        | Type               | Mandatory  | Description      |
| ----------- | ------------------- | ---- | -------- |
| targetNames | Array&lt;string&gt; | Yes   | Name of the target bundle.|

**Return value**

| Type                    | Description                   |
| ---------------------- | --------------------- |
| 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 123 124 125 126 127 128 129 130 131 132 133 134
};
```

## 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**

| Name        | Type               | Mandatory  | Description      |
| ----------- | ------------------- | ---- | -------- |
| targetNames | Array&lt;string&gt; | Yes   | Name of the target bundle.|
| 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) => {
        if (err) {
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
};
```

## 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**

| Name                 | Type   | Mandatory  | Description                 |
| -------------------- | ------- | ---- | ------------------- |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
}
```

## 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**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback    | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the current focus element.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let focusElement;
try {
    axContext.getFocusElement((err, data) => {
        if (err) {
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 239 240 241 242 243 244 245 246 247 248 249 250 251
}
```

## 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**

| 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.|

**Example**

```ts
let focusElement;
let isAccessibilityFocus = true;
try {
    axContext.getFocusElement(isAccessibilityFocus, (err, data) => {
    if (err) {
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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
}
```
## 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**

| Name                 | Type   | Mandatory  | Description                 |
| -------------------- | ------- | ---- | ------------------- |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
}
```

## 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**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback    | AsyncCallback&lt;AccessibilityElement&gt; | Yes   | Callback used to return the root element.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let rootElement;
try {
    axContext.getWindowRootElement((err, data) => {
    if (err) {
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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
}
```

## 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**

| 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.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let rootElement;
let windowId = 10;
try {
    axContext.getWindowRootElement(windowId, (err, data) => {
    if (err) {
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 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
}
```

## 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**

| Name                 | Type   | Mandatory  | Description                 |
| -------------------- | ------- | ---- | ------------------- |
| 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**

| Type                                 | Description                    |
| ----------------------------------- | ---------------------- |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
}
```

## AccessibilityExtensionContext.getWindows

getWindows(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**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback    | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | Yes   | Callback used to return the window list.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let windows;
try {
    axContext.getWindows((err, data) => {
        if (err) {
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 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
}
```

## 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**

| 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.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |

**Example**

```ts
let windows;
let displayId = 10;
try {
    axContext.getWindows(displayId, (err, data) => {
        if (err) {
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 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544
}
```

## 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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes   | Path of the gesture to inject.    |

**Return value**

| Type                                 | Description                    |
| ----------------------------------- | ---------------------- |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
}
```
## 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**

| 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.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 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 597
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) => {
        if (err) {
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 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
}
```
## 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

## attributeNames

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**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
});
```
## attributeNames

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| callback    | AsyncCallback&lt;Array&lt;T&gt;&gt;                  | Yes   | Callback used to return all attribute names of the element.|

**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 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
        return;
    }
    attributeNames = data;
    console.info('get attribute names success');
});
```
## AccessibilityElement.attributeValue

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| attributeName | T | Yes   | Attribute name.    |

**Return value**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
}
```
## AccessibilityElement.attributeValue

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| attributeName | T | Yes   | Attribute name.    |
| callback    | AsyncCallback&lt;ElementAttributeValues[T]&gt;   | Yes   | Callback used to return the attribute value.|

**Error codes**

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

| ID| Error Message|
| ------- | -------------------------------- |
| 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 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
}
```
## actionNames

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**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
});
```
## actionNames

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**

| 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.|

**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 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
        return;
    }
    actionNames = data;
    console.info('get action names success');
});
```
## performAction

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            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| actionName | string | Yes   | Action name.    |
| parameters | object | No   | Parameter required for performing the target action.    |

**Return value**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
}
```
## performAction

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            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| actionName | string | Yes   | Attribute name.    |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
}
```
## performAction

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| actionName | string | Yes   | Action name.    |
| parameters | object | Yes   | Parameter required for performing the target action.    |
| 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).

| ID| Error Message|
| ------- | -------------------------------- |
| 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 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967
}
```
## findElement('content')

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| type | string | Yes   | Information type. The value is fixed at **'content'**.    |
| condition | string | Yes   | Search criteria.    |

**Return value**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
}
```
## findElement('content')

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**

| 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.|

**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 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042
}
```
## findElement('focusType')

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| type | string | Yes   | Information type. The value is fixed at **'focusType'**.    |
| condition | [FocusType](#focustype) | Yes   | Enumerates the focus types.    |

**Return value**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
}
```
## findElement('focusType')

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**

| 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.|

**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 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
}
```
## findElement('focusDirection')

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**

| Name        | Type                                    | Mandatory  | Description            |
| ----------- | ---------------------------------------- | ---- | -------------- |
| type | string | Yes   | Information type. The value is fixed at **'focusDirection'**.    |
| condition | [FocusDirection](#focusdirection) | Yes   | Enumerates the focus directions.    |

**Return value**

| Type                                      | Description                      |
| ---------------------------------------- | ------------------------ |
| 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 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
}
```
## findElement('focusDirection')

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**

| 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.|

**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
}
```