1# AccessibilityExtensionContext (Accessibility Extension Context) 2 3The **AccessibilityExtensionContext** module, inherited from **ExtensionContext**, provides context for **Accessibility Extension** abilities. 4 5You can use the APIs of this module to configure the concerned information, obtain root information, and inject gestures. 6 7> **NOTE** 8> 9> 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. 10> 11> The APIs of this module can be used only in the stage model. 12 13## Usage 14 15Before using the **AccessibilityExtensionContext** module, you must define a child class that inherits from **AccessibilityExtensionAbility**. 16 17```ts 18import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'; 19let axContext; 20class MainAbility extends AccessibilityExtensionAbility { 21 onConnect(): void { 22 console.log('AxExtensionAbility onConnect'); 23 axContext = this.context; 24 } 25} 26``` 27 28## FocusDirection 29 30Enumerates the focus directions. 31 32**System capability**: SystemCapability.BarrierFree.Accessibility.Core 33 34| Name | Description | 35| -------- | ------- | 36| up | Search for the next focusable item above the current item in focus.| 37| down | Search for the next focusable item below the current item in focus.| 38| left | Search for the next focusable item on the left of the current item in focus.| 39| right | Search for the next focusable item on the right of the current item in focus.| 40| forward | Search for the next focusable item before the current item in focus.| 41| backward | Search for the next focusable item after the current item in focus.| 42 43## FocusType 44 45Enumerates the focus types. 46 47**System capability**: SystemCapability.BarrierFree.Accessibility.Core 48 49| Name | Description | 50| ------------- | ----------- | 51| accessibility | Accessibility focus.| 52| normal | Normal focus. | 53 54## Rect 55 56Defines a rectangle. 57 58**System capability**: SystemCapability.BarrierFree.Accessibility.Core 59 60| Name | Type | Readable | Writable | Description | 61| ------ | ------ | ---- | ---- | --------- | 62| left | number | Yes | No | Left boundary of the rectangle.| 63| top | number | Yes | No | Top boundary of the rectangle.| 64| width | number | Yes | No | Width of the rectangle. | 65| height | number | Yes | No | Height of the rectangle. | 66 67## WindowType 68 69Enumerates the window types. 70 71**System capability**: SystemCapability.BarrierFree.Accessibility.Core 72 73| Name | Description | 74| ----------- | --------- | 75| application | Application window.| 76| system | System window.| 77 78## AccessibilityExtensionContext.setTargetBundleName 79 80setTargetBundleName(targetNames: Array\<string>): Promise\<void>; 81 82Sets the concerned target bundle. This API uses a promise to return the result. 83 84**System capability**: SystemCapability.BarrierFree.Accessibility.Core 85 86**Parameters** 87 88| Name | Type | Mandatory | Description | 89| ----------- | ------------------- | ---- | -------- | 90| targetNames | Array<string> | Yes | Name of the target bundle.| 91 92**Return value** 93 94| Type | Description | 95| ---------------------- | --------------------- | 96| Promise<void> | Promise that returns no value.| 97 98**Example** 99 100```ts 101let targetNames = ['com.ohos.xyz']; 102try { 103 axContext.setTargetBundleName(targetNames).then(() => { 104 console.info('set target bundle names success'); 105 }).catch((err) => { 106 console.error('failed to set target bundle names, because ' + JSON.stringify(err)); 107 }); 108} catch (exception) { 109 console.error('failed to set target bundle names, because ' + JSON.stringify(exception)); 110}; 111``` 112 113## AccessibilityExtensionContext.setTargetBundleName 114 115setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>): void; 116 117Sets the concerned target bundle. This API uses an asynchronous callback to return the result. 118 119**System capability**: SystemCapability.BarrierFree.Accessibility.Core 120 121**Parameters** 122 123| Name | Type | Mandatory | Description | 124| ----------- | ------------------- | ---- | -------- | 125| targetNames | Array<string> | Yes | Name of the target bundle.| 126| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, **error** that contains data is returned.| 127 128**Example** 129 130```ts 131let targetNames = ['com.ohos.xyz']; 132try { 133 axContext.setTargetBundleName(targetNames, (err, data) => { 134 if (err) { 135 console.error('failed to set target bundle names, because ' + JSON.stringify(err)); 136 return; 137 } 138 console.info('set target bundle names success'); 139 }); 140} catch (exception) { 141 console.error('failed to set target bundle names, because ' + JSON.stringify(exception)); 142}; 143``` 144 145## AccessibilityExtensionContext.getFocusElement 146 147getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>; 148 149Obtains the focus element. This API uses a promise to return the result. 150 151**System capability**: SystemCapability.BarrierFree.Accessibility.Core 152 153**Parameters** 154 155| Name | Type | Mandatory | Description | 156| -------------------- | ------- | ---- | ------------------- | 157| isAccessibilityFocus | boolean | No | Whether the obtained focus element is an accessibility focus. The default value is **false**.| 158 159**Return value** 160 161| Type | Description | 162| ----------------------------------- | ---------------------- | 163| Promise<AccessibilityElement> | Promise used to return the current focus element.| 164 165**Error codes** 166 167For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 168 169| ID| Error Message| 170| ------- | -------------------------------- | 171| 9300003 | Do not have accessibility right for this operation. | 172 173**Example** 174 175```ts 176let focusElement; 177try { 178 axContext.getFocusElement().then((data) => { 179 focusElement = data; 180 console.log('get focus element success'); 181 }).catch((err) => { 182 console.error('failed to get focus element, because ' + JSON.stringify(err)); 183 }); 184} catch (exception) { 185 console.error('failed to get focus element, because ' + JSON.stringify(exception)); 186} 187``` 188 189## AccessibilityExtensionContext.getFocusElement 190 191getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void; 192 193Obtains the focus element. This API uses an asynchronous callback to return the result. 194 195**System capability**: SystemCapability.BarrierFree.Accessibility.Core 196 197**Parameters** 198 199| Name| Type| Mandatory| Description| 200| -------- | -------- | -------- | -------- | 201| callback | AsyncCallback<AccessibilityElement> | Yes | Callback used to return the current focus element.| 202 203**Error codes** 204 205For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 206 207| ID| Error Message| 208| ------- | -------------------------------- | 209| 9300003 | Do not have accessibility right for this operation. | 210 211**Example** 212 213```ts 214let focusElement; 215try { 216 axContext.getFocusElement((err, data) => { 217 if (err) { 218 console.error('failed to get focus element, because ' + JSON.stringify(err)); 219 return; 220 } 221 focusElement = data; 222 console.info('get focus element success'); 223 }); 224} catch (exception) { 225 console.error('failed to get focus element, because ' + JSON.stringify(exception)); 226} 227``` 228 229## AccessibilityExtensionContext.getFocusElement 230 231getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<AccessibilityElement>): void; 232 233Obtains the focus element. This API uses an asynchronous callback to return the result. 234 235**System capability**: SystemCapability.BarrierFree.Accessibility.Core 236 237**Parameters** 238 239| Name | Type | Mandatory | Description | 240| -------------------- | ------- | ---- | ------------------- | 241| isAccessibilityFocus | boolean | Yes | Whether the obtained focus element is an accessibility focus.| 242| callback | AsyncCallback<AccessibilityElement> | Yes | Callback used to return the current focus element.| 243 244**Example** 245 246```ts 247let focusElement; 248let isAccessibilityFocus = true; 249try { 250 axContext.getFocusElement(isAccessibilityFocus, (err, data) => { 251 if (err) { 252 console.error('failed to get focus element, because ' + JSON.stringify(err)); 253 return; 254 } 255 focusElement = data; 256 console.info('get focus element success'); 257}); 258} catch (exception) { 259 console.error('failed to get focus element, because ' + JSON.stringify(exception)); 260} 261``` 262## AccessibilityExtensionContext.getWindowRootElement 263 264getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>; 265 266Obtains the root element of a window. This API uses a promise to return the result. 267 268**System capability**: SystemCapability.BarrierFree.Accessibility.Core 269 270**Parameters** 271 272| Name | Type | Mandatory | Description | 273| -------------------- | ------- | ---- | ------------------- | 274| 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.| 275 276**Return value** 277 278| Type | Description | 279| ----------------------------------- | ---------------------- | 280| Promise<AccessibilityElement> | Promise used to return the root element.| 281 282**Error codes** 283 284For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 285 286| ID| Error Message| 287| ------- | -------------------------------- | 288| 9300003 | Do not have accessibility right for this operation. | 289 290**Example** 291 292```ts 293let rootElement; 294try { 295 axContext.getWindowRootElement().then((data) => { 296 rootElement = data; 297 console.log('get root element of the window success'); 298 }).catch((err) => { 299 console.error('failed to get root element of the window, because ' + JSON.stringify(err)); 300 }); 301} catch (exception) { 302 console.error('failed to get root element of the window, ' + JSON.stringify(exception)); 303} 304``` 305 306## AccessibilityExtensionContext.getWindowRootElement 307 308getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void; 309 310Obtains the root element of a window. This API uses an asynchronous callback to return the result. 311 312**System capability**: SystemCapability.BarrierFree.Accessibility.Core 313 314**Parameters** 315 316| Name| Type| Mandatory| Description| 317| -------- | -------- | -------- | -------- | 318| callback | AsyncCallback<AccessibilityElement> | Yes | Callback used to return the root element.| 319 320**Error codes** 321 322For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 323 324| ID| Error Message| 325| ------- | -------------------------------- | 326| 9300003 | Do not have accessibility right for this operation. | 327 328**Example** 329 330```ts 331let rootElement; 332try { 333 axContext.getWindowRootElement((err, data) => { 334 if (err) { 335 console.error('failed to get root element of the window, because ' + JSON.stringify(err)); 336 return; 337 } 338 rootElement = data; 339 console.info('get root element of the window success'); 340}); 341} catch (exception) { 342 console.error('failed to get root element of the window, because ' + JSON.stringify(exception)); 343} 344``` 345 346## AccessibilityExtensionContext.getWindowRootElement 347 348getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityElement>): void; 349 350Obtains the root element of a window. This API uses an asynchronous callback to return the result. 351 352**System capability**: SystemCapability.BarrierFree.Accessibility.Core 353 354**Parameters** 355 356| Name | Type | Mandatory | Description | 357| -------------------- | ------- | ---- | ------------------- | 358| 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.| 359| callback | AsyncCallback<AccessibilityElement> | Yes | Callback used to return the root element.| 360 361**Error codes** 362 363For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 364 365| ID| Error Message| 366| ------- | -------------------------------- | 367| 9300003 | Do not have accessibility right for this operation. | 368 369**Example** 370 371```ts 372let rootElement; 373let windowId = 10; 374try { 375 axContext.getWindowRootElement(windowId, (err, data) => { 376 if (err) { 377 console.error('failed to get root element of the window, because ' + JSON.stringify(err)); 378 return; 379 } 380 rootElement = data; 381 console.info('get root element of the window success'); 382}); 383} catch (exception) { 384 console.error('failed to get root element of the window, because ' + JSON.stringify(exception)); 385} 386``` 387 388## AccessibilityExtensionContext.getWindows 389 390getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>; 391 392Obtains the list of windows on a display. This API uses a promise to return the result. 393 394**System capability**: SystemCapability.BarrierFree.Accessibility.Core 395 396**Parameters** 397 398| Name | Type | Mandatory | Description | 399| -------------------- | ------- | ---- | ------------------- | 400| 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.| 401 402**Return value** 403 404| Type | Description | 405| ----------------------------------- | ---------------------- | 406| Promise<Array<AccessibilityElement>> | Promise used to return the window list.| 407 408**Error codes** 409 410For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 411 412| ID| Error Message| 413| ------- | -------------------------------- | 414| 9300003 | Do not have accessibility right for this operation. | 415 416**Example** 417 418```ts 419let windows; 420try { 421 axContext.getWindows().then((data) => { 422 windows = data; 423 console.log('get windows success'); 424 }).catch((err) => { 425 console.error('failed to get windows, because ' + JSON.stringify(err)); 426 }); 427} catch (exception) { 428 console.error('failed to get windows, because ' + JSON.stringify(exception)); 429} 430``` 431 432## AccessibilityExtensionContext.getWindows 433 434getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void; 435 436Obtains the list of windows on a display. This API uses an asynchronous callback to return the result. 437 438**System capability**: SystemCapability.BarrierFree.Accessibility.Core 439 440**Parameters** 441 442| Name| Type| Mandatory| Description| 443| -------- | -------- | -------- | -------- | 444| callback | AsyncCallback<Array<AccessibilityElement>> | Yes | Callback used to return the window list.| 445 446**Error codes** 447 448For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 449 450| ID| Error Message| 451| ------- | -------------------------------- | 452| 9300003 | Do not have accessibility right for this operation. | 453 454**Example** 455 456```ts 457let windows; 458try { 459 axContext.getWindows((err, data) => { 460 if (err) { 461 console.error('failed to get windows, because ' + JSON.stringify(err)); 462 return; 463 } 464 windows = data; 465 console.info('get windows success'); 466 }); 467} catch (exception) { 468 console.error('failed to get windows, because ' + JSON.stringify(exception)); 469} 470``` 471 472## AccessibilityExtensionContext.getWindows 473 474getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityElement>>): void; 475 476Obtains the list of windows on a display. This API uses an asynchronous callback to return the result. 477 478**System capability**: SystemCapability.BarrierFree.Accessibility.Core 479 480**Parameters** 481 482| Name | Type | Mandatory | Description | 483| -------------------- | ------- | ---- | ------------------- | 484| 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.| 485| callback | AsyncCallback<Array<AccessibilityElement>> | Yes | Callback used to return the window list.| 486 487**Error codes** 488 489For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 490 491| ID| Error Message| 492| ------- | -------------------------------- | 493| 9300003 | Do not have accessibility right for this operation. | 494 495**Example** 496 497```ts 498let windows; 499let displayId = 10; 500try { 501 axContext.getWindows(displayId, (err, data) => { 502 if (err) { 503 console.error('failed to get windows, because ' + JSON.stringify(err)); 504 return; 505 } 506 windows = data; 507 console.info('get windows success'); 508 }); 509} catch (exception) { 510 console.error('failed to get windows, because ' + JSON.stringify(exception)); 511} 512``` 513 514## AccessibilityExtensionContext.injectGesture 515 516injectGesture(gesturePath: GesturePath): Promise\<void>; 517 518Inject a gesture. This API uses a promise to return the result. 519 520**System capability**: SystemCapability.BarrierFree.Accessibility.Core 521 522**Parameters** 523 524| Name | Type | Mandatory | Description | 525| ----------- | ---------------------------------------- | ---- | -------------- | 526| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes | Path of the gesture to inject. | 527 528**Return value** 529 530| Type | Description | 531| ----------------------------------- | ---------------------- | 532| Promise<void> | Promise that returns no value.| 533 534**Error codes** 535 536For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 537 538| ID| Error Message| 539| ------- | -------------------------------- | 540| 9300003 | Do not have accessibility right for this operation. | 541 542**Example** 543 544```ts 545import GesturePath from '@ohos.accessibility.GesturePath'; 546import GesturePoint from '@ohos.accessibility.GesturePoint'; 547let gesturePath = new GesturePath.GesturePath(100); 548try { 549 for (let i = 0; i < 10; i++) { 550 let gesturePoint = new GesturePoint.GesturePoint(100, i * 200); 551 gesturePath.points.push(gesturePoint); 552 } 553 axContext.injectGesture(gesturePath).then(() => { 554 console.info('inject gesture success'); 555 }).catch((err) => { 556 console.error('failed to inject gesture, because ' + JSON.stringify(err)); 557 }); 558} catch (exception) { 559 console.error('failed to inject gesture, because ' + JSON.stringify(exception)); 560} 561``` 562## AccessibilityExtensionContext.injectGesture 563 564injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void 565 566Inject a gesture. This API uses an asynchronous callback to return the result. 567 568**System capability**: SystemCapability.BarrierFree.Accessibility.Core 569 570**Parameters** 571 572| Name | Type | Mandatory | Description | 573| ----------- | ---------------------------------------- | ---- | -------------- | 574| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | Yes | Path of the gesture to inject. | 575| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 576 577**Error codes** 578 579For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 580 581| ID| Error Message| 582| ------- | -------------------------------- | 583| 9300003 | Do not have accessibility right for this operation. | 584 585**Example** 586 587```ts 588import GesturePath from '@ohos.accessibility.GesturePath'; 589import GesturePoint from '@ohos.accessibility.GesturePoint'; 590let gesturePath = new GesturePath.GesturePath(100); 591try { 592 for (let i = 0; i < 10; i++) { 593 let gesturePoint = new GesturePoint.GesturePoint(100, i * 200); 594 gesturePath.points.push(gesturePoint); 595 } 596 axContext.injectGesture(gesturePath, (err, data) => { 597 if (err) { 598 console.error('failed to inject gesture, because ' + JSON.stringify(err)); 599 return; 600 } 601 console.info('inject gesture success'); 602 }); 603} catch (exception) { 604 console.error('failed to inject gesture, because ' + JSON.stringify(exception)); 605} 606``` 607## AccessibilityElement<sup>9+</sup> 608 609Defines the accessibilityelement. Before calling APIs of **AccessibilityElement**, you must call [AccessibilityExtensionContext.getFocusElement()](#accessibilityextensioncontextgetfocuselement) or [AccessibilityExtensionContext.getWindowRootElement()](#accessibilityextensioncontextgetwindowrootelement) to obtain an **AccessibilityElement** instance. 610 611**System capability**: SystemCapability.BarrierFree.Accessibility.Core 612 613## attributeNames 614 615attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>; 616 617Obtains all attribute names of this element. This API uses a promise to return the result. 618 619**System capability**: SystemCapability.BarrierFree.Accessibility.Core 620 621**Return value** 622 623| Type | Description | 624| ---------------------------------------- | ------------------------ | 625| Promise<Array<T>> | Promise used to return all attribute names of the element.| 626 627**Example** 628 629```ts 630let rootElement; 631let attributeNames; 632rootElement.attributeNames().then((data) => { 633 console.log('get attribute names success'); 634 attributeNames = data; 635}).catch((err) => { 636 console.log('failed to get attribute names, because ' + JSON.stringify(err)); 637}); 638``` 639## attributeNames 640 641attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\<Array\<T>>): void; 642 643Obtains all attribute names of this element. This API uses an asynchronous callback to return the result. 644 645**System capability**: SystemCapability.BarrierFree.Accessibility.Core 646 647**Parameters** 648 649| Name | Type | Mandatory | Description | 650| ----------- | ---------------------------------------- | ---- | -------------- | 651| callback | AsyncCallback<Array<T>> | Yes | Callback used to return all attribute names of the element.| 652 653**Example** 654 655```ts 656let rootElement; 657let attributeNames; 658rootElement.attributeNames((err, data) => { 659 if (err) { 660 console.error('failed to get attribute names, because ' + JSON.stringify(err)); 661 return; 662 } 663 attributeNames = data; 664 console.info('get attribute names success'); 665}); 666``` 667## AccessibilityElement.attributeValue 668 669attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promise\<ElementAttributeValues[T]>; 670 671Obtains the attribute value based on an attribute name. This API uses a promise to return the result. 672 673**System capability**: SystemCapability.BarrierFree.Accessibility.Core 674 675**Parameters** 676 677| Name | Type | Mandatory | Description | 678| ----------- | ---------------------------------------- | ---- | -------------- | 679| attributeName | T | Yes | Attribute name. | 680 681**Return value** 682 683| Type | Description | 684| ---------------------------------------- | ------------------------ | 685| Promise<ElementAttributeValues[T]> | Promise used to return the attribute value.| 686 687**Error codes** 688 689For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 690 691| ID| Error Message| 692| ------- | -------------------------------- | 693| 9300004 | This property does not exist. | 694 695**Example** 696 697```ts 698let attributeName = 'name'; 699let attributeValue; 700let rootElement; 701try { 702 rootElement.attributeValue(attributeName).then((data) => { 703 console.log('get attribute value by name success'); 704 attributeValue = data; 705 }).catch((err) => { 706 console.log('failed to get attribute value, because ' + JSON.stringify(err)); 707 }); 708} catch (exception) { 709 console.log('failed to get attribute value, because ' + JSON.stringify(exception)); 710} 711``` 712## AccessibilityElement.attributeValue 713 714attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T, 715 callback: AsyncCallback\<ElementAttributeValues[T]>): void; 716 717Obtains the attribute value based on an attribute name. This API uses an asynchronous callback to return the result. 718 719**System capability**: SystemCapability.BarrierFree.Accessibility.Core 720 721**Parameters** 722 723| Name | Type | Mandatory | Description | 724| ----------- | ---------------------------------------- | ---- | -------------- | 725| attributeName | T | Yes | Attribute name. | 726| callback | AsyncCallback<ElementAttributeValues[T]> | Yes | Callback used to return the attribute value.| 727 728**Error codes** 729 730For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 731 732| ID| Error Message| 733| ------- | -------------------------------- | 734| 9300004 | This property does not exist. | 735 736**Example** 737 738```ts 739let rootElement; 740let attributeValue; 741let attributeName = 'name'; 742try { 743 rootElement.attributeValue(attributeName, (err, data) => { 744 if (err) { 745 console.error('failed to get attribute value, because ' + JSON.stringify(err)); 746 return; 747 } 748 attributeValue = data; 749 console.info('get attribute value success'); 750 }); 751} catch (exception) { 752 console.log('failed to get attribute value, because ' + JSON.stringify(exception)); 753} 754``` 755## actionNames 756 757actionNames(): Promise\<Array\<string>>; 758 759Obtains the names of all actions supported by this element. This API uses a promise to return the result. 760 761**System capability**: SystemCapability.BarrierFree.Accessibility.Core 762 763**Return value** 764 765| Type | Description | 766| ---------------------------------------- | ------------------------ | 767| Promise<Array<string>> | Promise used to return the names of all actions supported by the element.| 768 769**Example** 770 771```ts 772let rootElement; 773let actionNames; 774rootElement.actionNames().then((data) => { 775 console.log('get action names success'); 776 actionNames = data; 777}).catch((err) => { 778 console.log('failed to get action names because ' + JSON.stringify(err)); 779}); 780``` 781## actionNames 782 783actionNames(callback: AsyncCallback\<Array\<string>>): void; 784 785Obtains the names of all actions supported by this element. This API uses an asynchronous callback to return the result. 786 787**System capability**: SystemCapability.BarrierFree.Accessibility.Core 788 789**Parameters** 790 791| Name | Type | Mandatory | Description | 792| ----------- | ---------------------------------------- | ---- | -------------- | 793| callback | AsyncCallback<Array<string>> | Yes | Callback used to return the names of all actions supported by the element.| 794 795**Example** 796 797```ts 798let rootElement; 799let actionNames; 800rootElement.actionNames((err, data) => { 801 if (err) { 802 console.error('failed to get action names, because ' + JSON.stringify(err)); 803 return; 804 } 805 actionNames = data; 806 console.info('get action names success'); 807}); 808``` 809## performAction 810 811performAction(actionName: string, parameters?: object): Promise\<void>; 812 813Performs an action based on the specified action name. This API uses a promise to return the result. 814 815**System capability**: SystemCapability.BarrierFree.Accessibility.Core 816 817**Parameters** 818 819| Name | Type | Mandatory | Description | 820| ----------- | ---------------------------------------- | ---- | -------------- | 821| actionName | string | Yes | Action name. | 822| parameters | object | No | Parameter required for performing the target action. | 823 824**Return value** 825 826| Type | Description | 827| ---------------------------------------- | ------------------------ | 828| Promise<void> | Promise that returns no value.| 829 830**Error codes** 831 832For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 833 834| ID| Error Message| 835| ------- | -------------------------------- | 836| 9300005 | This action is not supported. | 837 838**Example** 839 840```ts 841let rootElement; 842try { 843 rootElement.performAction('action').then((data) => { 844 console.info('perform action success'); 845 }).catch((err) => { 846 console.log('failed to perform action, because ' + JSON.stringify(err)); 847 }); 848} catch (exception) { 849 console.log('failed to perform action, because ' + JSON.stringify(exception)); 850} 851``` 852## performAction 853 854performAction(actionName: string, callback: AsyncCallback\<void>): void; 855 856Performs an action based on the specified action name. This API uses an asynchronous callback to return the result. 857 858**System capability**: SystemCapability.BarrierFree.Accessibility.Core 859 860**Parameters** 861 862| Name | Type | Mandatory | Description | 863| ----------- | ---------------------------------------- | ---- | -------------- | 864| actionName | string | Yes | Attribute name. | 865| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 866 867**Error codes** 868 869For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 870 871| ID| Error Message| 872| ------- | -------------------------------- | 873| 9300005 | This action is not supported. | 874 875**Example** 876 877```ts 878let rootElement; 879try { 880 rootElement.performAction('action', (err, data) => { 881 if (err) { 882 console.error('failed to perform action, because ' + JSON.stringify(err)); 883 return; 884 } 885 console.info('perform action success'); 886 }); 887} catch (exception) { 888 console.log('failed to perform action, because ' + JSON.stringify(exception)); 889} 890``` 891## performAction 892 893performAction(actionName: string, parameters: object, callback: AsyncCallback\<void>): void; 894 895Performs an action based on the specified action name. This API uses an asynchronous callback to return the result. 896 897**System capability**: SystemCapability.BarrierFree.Accessibility.Core 898 899**Parameters** 900 901| Name | Type | Mandatory | Description | 902| ----------- | ---------------------------------------- | ---- | -------------- | 903| actionName | string | Yes | Action name. | 904| parameters | object | Yes | Parameter required for performing the target action. | 905| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 906 907**Error codes** 908 909For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md). 910 911| ID| Error Message| 912| ------- | -------------------------------- | 913| 9300005 | This action is not supported. | 914 915**Example** 916 917```ts 918let rootElement; 919let actionName = 'action'; 920let parameters = { 921 'setText': 'test text' 922}; 923try { 924 rootElement.performAction(actionName, parameters, (err, data) => { 925 if (err) { 926 console.error('failed to perform action, because ' + JSON.stringify(err)); 927 return; 928 } 929 console.info('perform action success'); 930 }); 931} catch (exception) { 932 console.log('failed to perform action, because ' + JSON.stringify(exception)); 933} 934``` 935## findElement('content') 936 937findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>; 938 939Queries the element information of the **content** type. This API uses a promise to return the result. 940 941**System capability**: SystemCapability.BarrierFree.Accessibility.Core 942 943**Parameters** 944 945| Name | Type | Mandatory | Description | 946| ----------- | ---------------------------------------- | ---- | -------------- | 947| type | string | Yes | Information type. The value is fixed at **'content'**. | 948| condition | string | Yes | Search criteria. | 949 950**Return value** 951 952| Type | Description | 953| ---------------------------------------- | ------------------------ | 954| Promise<Array<AccessibilityElement>> | Promise used to return the result.| 955 956**Example** 957 958```ts 959let rootElement; 960let type = 'content'; 961let condition = 'keyword'; 962let elements; 963try { 964 rootElement.findElement(type, condition).then((data) => { 965 elements = data; 966 console.log('find element success'); 967 }).catch((err) => { 968 console.log('failed to find element, because ' + JSON.stringify(err)); 969 }); 970} catch (exception) { 971 console.log('failed to find element, because ' + JSON.stringify(exception)); 972} 973``` 974## findElement('content') 975 976findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<AccessibilityElement>>): void; 977 978Queries the element information of the **content** type. This API uses an asynchronous callback to return the result. 979 980**System capability**: SystemCapability.BarrierFree.Accessibility.Core 981 982**Parameters** 983 984| Name | Type | Mandatory | Description | 985| ----------- | ---------------------------------------- | ---- | -------------- | 986| type | string | Yes | Information type. The value is fixed at **'content'**. | 987| condition | string | Yes | Search criteria. | 988| callback | AsyncCallback<Array<AccessibilityElement>> | Yes | Callback used to return the result.| 989 990**Example** 991 992```ts 993let rootElement; 994let type = 'content'; 995let condition = 'keyword'; 996let elements; 997try { 998 rootElement.findElement(type, condition, (err, data) => { 999 if (err) { 1000 console.error('failed to find element, because ' + JSON.stringify(err)); 1001 return; 1002 } 1003 elements = data; 1004 console.info('find element success'); 1005 }); 1006} catch (exception) { 1007 console.log('failed to find element, because ' + JSON.stringify(exception)); 1008} 1009``` 1010## findElement('focusType') 1011 1012findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>; 1013 1014Queries the element information of the **focusType** type. This API uses a promise to return the result. 1015 1016**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1017 1018**Parameters** 1019 1020| Name | Type | Mandatory | Description | 1021| ----------- | ---------------------------------------- | ---- | -------------- | 1022| type | string | Yes | Information type. The value is fixed at **'focusType'**. | 1023| condition | [FocusType](#focustype) | Yes | Enumerates the focus types. | 1024 1025**Return value** 1026 1027| Type | Description | 1028| ---------------------------------------- | ------------------------ | 1029| Promise<AccessibilityElement> | Promise used to return the result.| 1030 1031**Example** 1032 1033```ts 1034let rootElement; 1035let type = 'focusType'; 1036let condition = 'normal'; 1037let element; 1038try { 1039 rootElement.findElement(type, condition).then((data) => { 1040 element = data; 1041 console.log('find element success'); 1042 }).catch((err) => { 1043 console.log('failed to find element, because ' + JSON.stringify(err)); 1044 }); 1045} catch (exception) { 1046 console.log('failed to find element, because ' + JSON.stringify(exception)); 1047} 1048``` 1049## findElement('focusType') 1050 1051findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void; 1052 1053Queries the element information of the **focusType** type. This API uses an asynchronous callback to return the result. 1054 1055**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1056 1057**Parameters** 1058 1059| Name | Type | Mandatory | Description | 1060| ----------- | ---------------------------------------- | ---- | -------------- | 1061| type | string | Yes | Information type. The value is fixed at **'focusType'**. | 1062| condition | [FocusType](#focustype) | Yes | Enumerates the focus types. | 1063| callback | AsyncCallback<AccessibilityElement> | Yes | Callback used to return the result.| 1064 1065**Example** 1066 1067```ts 1068let rootElement; 1069let type = 'focusType'; 1070let condition = 'normal'; 1071let element; 1072try { 1073 rootElement.findElement(type, condition, (err, data) => { 1074 if (err) { 1075 console.error('failed to find element, because ' + JSON.stringify(err)); 1076 return; 1077 } 1078 element = data; 1079 console.info('find element success'); 1080 }); 1081} catch (exception) { 1082 console.log('failed to find element, because ' + JSON.stringify(exception)); 1083} 1084``` 1085## findElement('focusDirection') 1086 1087findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>; 1088 1089Queries the element information of the **focusDirection** type. This API uses a promise to return the result. 1090 1091**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1092 1093**Parameters** 1094 1095| Name | Type | Mandatory | Description | 1096| ----------- | ---------------------------------------- | ---- | -------------- | 1097| type | string | Yes | Information type. The value is fixed at **'focusDirection'**. | 1098| condition | [FocusDirection](#focusdirection) | Yes | Enumerates the focus directions. | 1099 1100**Return value** 1101 1102| Type | Description | 1103| ---------------------------------------- | ------------------------ | 1104| Promise<AccessibilityElement> | Promise used to return the result.| 1105 1106**Example** 1107 1108```ts 1109let rootElement; 1110let type = 'focusDirection'; 1111let condition = 'up'; 1112let element; 1113try { 1114 rootElement.findElement(type, condition).then((data) => { 1115 element = data; 1116 console.log('find element success'); 1117 }).catch((err) => { 1118 console.log('failed to find element, because ' + JSON.stringify(err)); 1119 }); 1120} catch (exception) { 1121 console.log('failed to find element, because ' + JSON.stringify(exception)); 1122} 1123``` 1124## findElement('focusDirection') 1125 1126findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void; 1127 1128Queries the element information of the **focusDirection** type. This API uses an asynchronous callback to return the result. 1129 1130**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1131 1132**Parameters** 1133 1134| Name | Type | Mandatory | Description | 1135| ----------- | ---------------------------------------- | ---- | -------------- | 1136| type | string | Yes | Information type. The value is fixed at **'focusDirection'**. | 1137| condition | [FocusDirection](#focusdirection) | Yes | Direction of the next focus element. | 1138| callback | AsyncCallback<AccessibilityElement> | Yes | Callback used to return the result.| 1139 1140**Example** 1141 1142```ts 1143let rootElement; 1144let type = 'focusDirection'; 1145let condition = 'up'; 1146let elements; 1147try { 1148 rootElement.findElement(type, condition, (err, data) => { 1149 if (err) { 1150 console.error('failed to find element, because ' + JSON.stringify(err)); 1151 return; 1152 } 1153 elements = data; 1154 console.info('find element success'); 1155 }); 1156} catch (exception) { 1157 console.log('failed to find element, because ' + JSON.stringify(exception)); 1158} 1159``` 1160