1# @ohos.accessibility (Accessibility) 2 3The **Accessibility** module implements the accessibility functions, including obtaining the accessibility application list, accessibility application enabled status, and captions configuration. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import accessibility from '@ohos.accessibility'; 13``` 14 15## AbilityState 16 17Enumerates the states of an accessibility application. 18 19**System capability**: SystemCapability.BarrierFree.Accessibility.Core 20 21| Name | Description | 22| ------- | -------- | 23| enable | The accessibility application is enabled.| 24| disable | The accessibility application is disabled.| 25| install | The accessibility application has been installed.| 26 27## AbilityType 28 29Enumerates the types of accessibility applications. 30 31**System capability**: SystemCapability.BarrierFree.Accessibility.Core 32 33| Name | Description | 34| ---------------- | --------- | 35| audible | The accessibility application provides audible feedback.| 36| generic | The accessibility application provides generic feedback.| 37| haptic | The accessibility application provides haptic feedback.| 38| spoken | The accessibility application provides spoken feedback.| 39| visual | The accessibility application provides visual feedback.| 40| all<sup>9+</sup> | All the preceding types.| 41 42## AccessibilityAbilityInfo 43 44Provides information about an accessibility application. 45 46**System capability**: SystemCapability.BarrierFree.Accessibility.Core 47 48### Attributes 49 50| Name | Type | Readable | Writable | Description | 51| ------------------------------ | ---------------------------------------- | ---- | ---- | ---------------- | 52| id | string | Yes | No | Ability ID.| 53| name | string | Yes | No | Ability name. | 54| bundleName | string | Yes | No | Bundle name. | 55| targetBundleNames<sup>9+</sup> | Array<string> | Yes | No | Name of the target bundle. | 56| abilityTypes | Array<[AbilityType](#abilitytype)> | Yes | No | Accessibility application type. | 57| capabilities | Array<[Capability](#capability)> | Yes | No | Capabilities list of the accessibility application. | 58| description | string | Yes | No | Description of the accessibility application. | 59| eventTypes | Array<[EventType](#eventtype)> | Yes | No | List of events that the accessibility application focuses on. | 60 61## Action 62 63Describes the target action supported by an accessibility application. 64 65**System capability**: SystemCapability.BarrierFree.Accessibility.Core 66 67| Name | Description | 68| ----------------------- | ------------------ | 69| click | Clicking. | 70| longClick | Long pressing. | 71| scrollForward | Scrolling forward. Not supported currently.| 72| scrollBackward | Scrolling backward. Not supported currently.| 73| focus | Obtaining focus. Not supported currently.| 74| clearFocus | Clearing focus. Not supported currently.| 75| clearSelection | Clearing selection. Not supported currently.| 76| accessibilityFocus | Obtaining the accessibility focus. | 77| clearAccessibilityFocus | Clearing the accessibility focus. | 78| cut | Cut. Not supported currently. | 79| copy | Copy. Not supported currently. | 80| paste | Paste. Not supported currently. | 81| select | Select. Not supported currently. | 82| setText | Setting the text. Not supported currently.| 83| delete | Delete. Not supported currently. | 84| setSelection | Setting the selection. Not supported currently. | 85 86## Capability 87 88Enumerates the capabilities of an accessibility application. 89 90**System capability**: SystemCapability.BarrierFree.Accessibility.Core 91 92| Name | Description | 93| ---------------- | --------------------- | 94| retrieve | Capability to retrieve the window content. | 95| touchGuide | Capability of touch guide mode. | 96| keyEventObserver | Capability to filter key events. | 97| zoom | Capability to control the display zoom level. Not supported currently.| 98| gesture | Capability to perform gesture actions. | 99 100## CaptionsFontEdgeType<sup>8+</sup> 101 102Enumerates the font edge types of captions. 103 104**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 105 106| Name | Description | 107| ---------- | ----- | 108| none | No effect. | 109| raised | Raised effect.| 110| depressed | Depressed effect.| 111| uniform | Uniform effect.| 112| dropShadow | Drop shadow effect.| 113 114## CaptionsFontFamily<sup>8+</sup> 115 116Enumerates the font families of captions. 117 118**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 119 120| Name | Description | 121| ------------------- | ----------------- | 122| default | Default font family. | 123| monospacedSerif | Monospaced Serif fonts, which use the same width for each character. | 124| serif | Serif fonts. | 125| monospacedSansSerif | Monospaced Sans Serif fonts, which use the same width for each character.| 126| sansSerif | Sans Serif fonts. | 127| casual | Casual fonts. | 128| cursive | Cursive fonts. | 129| smallCapitals | Small caps fonts. | 130 131## CaptionsStyle<sup>8+</sup> 132 133Describes the style of captions. 134 135**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 136 137| Name | Type | Readable | Writable | Description | 138| --------------- | ---------------------------------------- | ---- | ---- | ----------- | 139| fontFamily | [CaptionsFontFamily](#captionsfontfamily8) | Yes | No | Font family of captions. | 140| fontScale | number | Yes | No | Font scale factor of captions, in percentage. The value ranges from 1 to 200.| 141| fontColor | number \| string | Yes | No | Font color of captions. For example, red corresponds to #FF0000. | 142| fontEdgeType | [CaptionsFontEdgeType](#captionsfontedgetype8) | Yes | No | Font edge type of captions. | 143| backgroundColor | number \| string | Yes | No | Background color of captions. For example, red corresponds to #FF0000. | 144| windowColor | number \| string | Yes | No | Window color of captions. For example, red corresponds to #FF0000. | 145 146## CaptionsManager<sup>8+</sup> 147 148Implements configuration management for captions. Before calling any API of **CaptionsManager**, you must use the [accessibility.getCaptionsManager()](#accessibilitygetcaptionsmanager8) API to obtain a **CaptionsManager** instance. 149 150**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 151 152### Attributes 153 154| Name | Type | Readable | Writable | Description | 155| ------- | -------------------------------- | ---- | ---- | ----------- | 156| enabled | boolean | Yes | No | Whether to enable captions configuration.| 157| style | [CaptionsStyle](#captionsstyle8) | Yes | No | Style of captions. | 158 159### on('enableChange') 160 161on(type: 'enableChange', callback: Callback<boolean>): void; 162 163Enables listening for the enabled status changes of captions configuration. This API uses an asynchronous callback to return the result. 164 165**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 166 167**Parameters** 168 169| Name | Type | Mandatory | Description | 170| -------- | ----------------------- | ---- | --------------------------------------- | 171| type | string | Yes | Type of the event to listen for, which is set to **'enableChange'** in this API.| 172| callback | Callback<boolean> | Yes | Callback invoked when the enabled status of captions configuration changes. | 173 174**Example** 175 176```ts 177import accessibility from '@ohos.accessibility'; 178 179let captionsManager = accessibility.getCaptionsManager(); 180try { 181 captionsManager.on('enableChange', (data: boolean) => { 182 console.info('subscribe caption manager enable state change, result: ' + JSON.stringify(data)); 183 }); 184} catch (exception) { 185 console.error('failed to subscribe caption manager enable state change, because ' + JSON.stringify(exception)); 186} 187``` 188 189### on('styleChange') 190 191on(type: 'styleChange', callback: Callback<CaptionsStyle>): void; 192 193Enables listening for captions style changes. This API uses an asynchronous callback to return the result. 194 195**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 196 197**Parameters** 198 199| Name | Type | Mandatory | Description | 200| -------- | ---------------------------------------- | ---- | ---------------------------------- | 201| type | string | Yes | Type of the event to listen for, which is set to **'styleChange'** in this API.| 202| callback | Callback<[CaptionsStyle](#captionsstyle8)> | Yes | Callback invoked when the style of captions changes. | 203 204**Example** 205 206```ts 207import accessibility from '@ohos.accessibility'; 208 209let captionStyle: accessibility.CaptionsStyle; 210let captionsManager = accessibility.getCaptionsManager(); 211try { 212 captionsManager.on('styleChange', (data: accessibility.CaptionsStyle) => { 213 captionStyle = data; 214 console.info('subscribe caption manager style state change, result: ' + JSON.stringify(data)); 215 }); 216} catch (exception) { 217 console.error('failed to subscribe caption manager style state change, because ' + JSON.stringify(exception)); 218} 219``` 220 221### off('enableChange') 222 223off(type: 'enableChange', callback?: Callback<boolean>): void; 224 225Disables listening for the enabled status changes of captions configuration. This API uses an asynchronous callback to return the result. 226 227**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 228 229**Parameters** 230 231| Name | Type | Mandatory | Description | 232| -------- | ----------------------- | ---- | ---------------------------------------- | 233| type | string | Yes | Type of the event to listen for, which is set to **'enableChange'** in this API.| 234| callback | Callback<boolean> | No | Callback for the event. | 235 236**Example** 237 238```ts 239import accessibility from '@ohos.accessibility'; 240 241let captionsManager = accessibility.getCaptionsManager(); 242try { 243 captionsManager.off('enableChange', (data: boolean) => { 244 console.info('Unsubscribe caption manager enable state change, result: ' + JSON.stringify(data)); 245 }); 246} catch (exception) { 247 console.error('failed to Unsubscribe caption manager enable state change, because ' + JSON.stringify(exception)); 248} 249``` 250 251### off('styleChange') 252 253off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void; 254 255Disables listening for captions style changes. This API uses an asynchronous callback to return the result. 256 257**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 258 259**Parameters** 260 261| Name | Type | Mandatory | Description | 262| -------- | ---------------------------------------- | ---- | ------------------------------------ | 263| type | string | Yes | Type of the event to listen for, which is set to **'styleChange'** in this API.| 264| callback | Callback<[CaptionsStyle](#captionsstyle8)> | No | Callback for the event. | 265 266**Example** 267 268```ts 269import accessibility from '@ohos.accessibility'; 270 271let captionStyle: accessibility.CaptionsStyle; 272let captionsManager = accessibility.getCaptionsManager(); 273try { 274 captionsManager.off('styleChange', (data: accessibility.CaptionsStyle) => { 275 captionStyle = data; 276 console.info('Unsubscribe caption manager style state change, result: ' + JSON.stringify(data)); 277 }); 278} catch (exception) { 279 console.error('failed to Unsubscribe caption manager style state change, because ' + JSON.stringify(exception)); 280} 281``` 282 283## EventInfo 284 285Describes a GUI change event. 286 287**System capability**: SystemCapability.BarrierFree.Accessibility.Core 288 289### Attributes 290 291| Name | Type | Readable | Writable | Description | 292| ---------------- | ------------------------------------- | ---- | ---- | --------------------- | 293| type | [EventType](#eventtype) | Yes | Yes | Accessibility event type. | 294| windowUpdateType | [WindowUpdateType](#windowupdatetype) | Yes | Yes | Window update type. | 295| bundleName | string | Yes | Yes | Target application name. | 296| componentType | string | Yes | Yes | Type of the event source component, for example, button or chart. | 297| pageId | number | Yes | Yes | Page ID of the event source. | 298| description | string | Yes | Yes | Event description. Not supported currently. | 299| triggerAction | [Action](#action) | Yes | Yes | Action that triggers the event. | 300| textMoveUnit | [TextMoveUnit](#textmoveunit) | Yes | Yes | Text movement unit. Not supported currently. | 301| contents | Array<string> | Yes | Yes | Array of contents. | 302| lastContent | string | Yes | Yes | Latest content. | 303| beginIndex | number | Yes | Yes | Sequence number of the first item displayed on the page. Not supported currently.| 304| currentIndex | number | Yes | Yes | Sequence number of the current item. Not supported currently. | 305| endIndex | number | Yes | Yes | Sequence number of the last item displayed on the page. Not supported currently.| 306| itemCount | number | Yes | Yes | Total number of items. Not supported currently. | 307 308### constructor 309 310constructor(jsonObject) 311 312Implements a constructor. 313 314**System capability**: SystemCapability.BarrierFree.Accessibility.Core 315 316**Parameters** 317 318| Name | Type | Mandatory | Description | 319| ---------- | ------ | ---- | -------------------- | 320| jsonObject | string | Yes | JSON string required for creating an object.| 321 322**Example** 323 324 ```ts 325 import accessibility from '@ohos.accessibility'; 326 327 let eventInfo: accessibility.EventInfo = ({ 328 type: 'click', 329 bundleName: 'com.example.MyApplication', 330 triggerAction: 'click' 331 }); 332 ``` 333 334## EventType 335 336Enumerates accessibility event types. 337 338**System capability**: SystemCapability.BarrierFree.Accessibility.Core 339 340| Name | Description | 341| ----------------------- | ---------------------- | 342| click | Event of clicking a component. | 343| longClick | Event of long-pressing a component. | 344| select | Event of selecting a component. Not supported currently. | 345| focus | Event indicating that the component obtains the focus. Not supported currently. | 346| textUpdate | Event indicating that the component text has been updated. Not supported currently.| 347| hoverEnter | Event indicating that the hover enters a component. Not supported currently. | 348| hoverExit | Event indicating that the hover exits a component. Not supported currently. | 349| scroll | Event of the scroll view. Not supported currently. | 350| textSelectionUpdate | Event indicating that the selected text has been updated. Not supported currently.| 351| accessibilityFocus | Event indicating that the accessibility focus has been obtained. | 352| accessibilityFocusClear | Event indicating that the accessibility focus has been cleared. | 353 354## TextMoveUnit 355 356Enumerates the movement units for traversing the node text. 357 358**System capability**: SystemCapability.BarrierFree.Accessibility.Core 359 360| Name | Description | 361| --------- | --------------- | 362| char | The movement unit for traversing the node text is by character.| 363| word | The movement unit for traversing the node text is by word. | 364| line | The movement unit for traversing the node text is by line. | 365| page | The movement unit for traversing the node text is by page. | 366| paragraph | The movement unit for traversing the node text is by paragraph.| 367 368## WindowUpdateType 369 370Enumerates window update types. 371 372**System capability**: SystemCapability.BarrierFree.Accessibility.Core 373 374| Name | Description | 375| ------ | ------------------ | 376| add | Window adding. | 377| remove | Window deletion. | 378| bounds | Window boundary change. | 379| active | Window activity change.| 380| focus | Window focus change. | 381 382## accessibility.getAbilityLists<sup>(deprecated)</sup> 383 384getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>> 385 386Obtains the accessibility application list. This API uses a promise to return the result. 387 388> **NOTE** 389> 390> This API is supported since API version 7 and deprecated since API version 9. 391> You are advised to use[getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9). 392 393**System capability**: SystemCapability.BarrierFree.Accessibility.Core 394 395**Parameters** 396 397| Name | Type | Mandatory | Description | 398| ----------- | ----------------------------- | ---- | -------- | 399| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type.| 400| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status.| 401 402**Return value** 403 404| Type | Description | 405| ---------------------------------------- | --------------------- | 406| Promise<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Promise used to return the accessibility application list.| 407 408**Example** 409 410```ts 411import accessibility from '@ohos.accessibility'; 412 413let abilityType : accessibility.AbilityType = 'spoken'; 414let abilityState : accessibility.AbilityState = 'enable'; 415let abilityList: accessibility.AccessibilityAbilityInfo[]; 416try { 417 accessibility.getAbilityLists(abilityType, abilityState) 418 .then((data: accessibility.AccessibilityAbilityInfo[]) => { 419 for (let item of data) { 420 console.info(item.id); 421 console.info(item.name); 422 console.info(item.description); 423 console.info(item.bundleName); 424 abilityList.push(item); 425 } 426 console.info('get accessibility extension list success'); 427 }) 428 .catch((err: object) => { 429 console.error('failed to get accessibility extension list because ' + JSON.stringify(err)); 430 }); 431} catch (exception) { 432 console.error('failed to get accessibility extension list because ' + JSON.stringify(exception)); 433} 434``` 435 436## accessibility.getAbilityLists<sup>(deprecated)</sup> 437 438getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void 439 440Obtains the accessibility application list. This API uses an asynchronous callback to return the result. 441 442> **NOTE** 443> 444> This API is supported since API version 7 and deprecated since API version 9. 445> You are advised to use [getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9-1). 446 447**System capability**: SystemCapability.BarrierFree.Accessibility.Core 448 449**Parameters** 450 451| Name | Type | Mandatory | Description | 452| ----------- | ---------------------------------------- | ---- | ---------------- | 453| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type. | 454| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status. | 455| callback | AsyncCallback<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Yes | Callback used to return the accessibility application list.| 456 457**Example** 458 459```ts 460import accessibility from '@ohos.accessibility'; 461import { BusinessError } from '@ohos.base'; 462 463let abilityType : accessibility.AbilityType = 'spoken'; 464let abilityState : accessibility.AbilityState = 'enable'; 465let abilityList: accessibility.AccessibilityInfo[]; 466try { 467 accessibility.getAbilityLists(abilityType, abilityState, 468 (err: BusinessError<void>, data: accessibility.AccessibilityAbilityInfo[]) => { 469 if (err) { 470 console.error('failed to get accessibility extension list because ' + JSON.stringify(err)); 471 return; 472 } 473 for (let item of data) { 474 console.info(item.id); 475 console.info(item.name); 476 console.info(item.description); 477 console.info(item.bundleName); 478 abilityList.push(item); 479 } 480 console.info('get accessibility extension list success'); 481 }) 482} catch (exception) { 483 console.error('failed to get accessibility extension list because ' + JSON.stringify(exception)); 484} 485``` 486 487## accessibility.getAccessibilityExtensionList<sup>9+</sup> 488 489getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>> 490 491Obtains the accessibility application list. This API uses a promise to return the result. 492 493**System capability**: SystemCapability.BarrierFree.Accessibility.Core 494 495**Parameters** 496 497| Name | Type | Mandatory | Description | 498| ----------- | ----------------------------- | ---- | -------- | 499| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type.| 500| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status.| 501 502**Return value** 503 504| Type | Description | 505| ---------------------------------------- | --------------------- | 506| Promise<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Promise used to return the accessibility application list.| 507 508**Example** 509 510```ts 511import accessibility from '@ohos.accessibility'; 512 513let abilityType : accessibility.AbilityType = 'spoken'; 514let abilityState : accessibility.AbilityState = 'enable'; 515let extensionList: accessibility.AccessibilityAbilityInfo[] = []; 516try { 517 accessibility.getAccessibilityExtensionList(abilityType, abilityState) 518 .then((data: accessibility.AccessibilityAbilityInfo[]) => { 519 for (let item of data) { 520 console.info(item.id); 521 console.info(item.name); 522 console.info(item.description); 523 console.info(item.bundleName); 524 extensionList.push(item); 525 } 526 console.info('get accessibility extension list success'); 527 }) 528 .catch((err: object) => { 529 console.error('failed to get accessibility extension list because ' + JSON.stringify(err)); 530 }); 531} catch (exception) { 532 console.error('failed to get accessibility extension list because ' + JSON.stringify(exception)); 533} 534``` 535 536## accessibility.getAccessibilityExtensionList<sup>9+</sup> 537 538getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState, callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void 539 540Obtains the accessibility application list. This API uses an asynchronous callback to return the result. 541 542**System capability**: SystemCapability.BarrierFree.Accessibility.Core 543 544**Parameters** 545 546| Name | Type | Mandatory | Description | 547| ----------- | ---------------------------------------- | ---- | ---------------- | 548| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type. | 549| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status. | 550| callback | AsyncCallback<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Yes | Callback used to return the accessibility application list.| 551 552**Example** 553 554```ts 555import accessibility from '@ohos.accessibility'; 556import { BusinessError } from '@ohos.base'; 557 558let abilityType : accessibility.AbilityType = 'spoken'; 559let abilityState : accessibility.AbilityState = 'enable'; 560let extensionList: accessibility.AccessibilityAbilityInfo[] = []; 561try { 562 accessibility.getAccessibilityExtensionList(abilityType, abilityState, 563 (err: BusinessError<void>, data: accessibility.AccessibilityAbilityInfo[]) => { 564 if (err) { 565 console.error('failed to get accessibility extension list because ' + JSON.stringify(err)); 566 return; 567 } 568 for (let item of data) { 569 console.info(item.id); 570 console.info(item.name); 571 console.info(item.description); 572 console.info(item.bundleName); 573 extensionList.push(item); 574 } 575 console.info('get accessibility extension list success'); 576 }); 577} catch (exception) { 578 console.error('failed to get accessibility extension list because ' + JSON.stringify(exception)); 579} 580``` 581 582## accessibility.getCaptionsManager<sup>8+</sup> 583 584getCaptionsManager(): CaptionsManager 585 586Obtains a **CaptionsManager** instance. 587 588**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 589 590**Return value** 591 592| Type | Description | 593| ------------------------------------ | ---------- | 594| [CaptionsManager](#captionsmanager8) | Captions configuration.| 595 596**Example** 597 598```ts 599import accessibility from '@ohos.accessibility'; 600 601let captionsManager = accessibility.getCaptionsManager(); 602``` 603 604## accessibility.on('accessibilityStateChange') 605 606on(type: 'accessibilityStateChange', callback: Callback<boolean>): void 607 608Enables listening for the enabled status changes of the accessibility application. This API uses an asynchronous callback to return the result. 609 610**System capability**: SystemCapability.BarrierFree.Accessibility.Core 611 612**Parameters** 613 614| Name | Type | Mandatory | Description | 615| -------- | ----------------------- | ---- | ---------------------------------------- | 616| type | string | Yes | Type of the event to listen for, which is set to **'accessibilityStateChange'** in this API.| 617| callback | Callback<boolean> | Yes | Callback used to return the result. | 618 619**Example** 620 621```ts 622import accessibility from '@ohos.accessibility'; 623 624try { 625 accessibility.on('accessibilityStateChange', (data: boolean) => { 626 console.info('subscribe accessibility state change, result: ' + JSON.stringify(data)); 627 }); 628} catch (exception) { 629 console.error('failed to subscribe accessibility state change, because ' + JSON.stringify(exception)); 630} 631``` 632 633## accessibility.on('touchGuideStateChange') 634 635on(type: 'touchGuideStateChange', callback: Callback<boolean>): void 636 637Enables listening for the enabled status changes of the touch guide mode. This API uses an asynchronous callback to return the result. 638 639**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 640 641**Parameters** 642 643| Name | Type | Mandatory | Description | 644| -------- | ----------------------- | ---- | ---------------------------------------- | 645| type | string | Yes | Type of the event to listen for, which is set to **'touchGuideStateChange'** in this API.| 646| callback | Callback<boolean> | Yes | Callback used to return the result. | 647 648**Example** 649 650```ts 651import accessibility from '@ohos.accessibility'; 652 653try { 654 accessibility.on('touchGuideStateChange', (data: boolean) => { 655 console.info('subscribe touch guide state change, result: ' + JSON.stringify(data)); 656 }); 657} catch (exception) { 658 console.error('failed to subscribe touch guide state change, because ' + JSON.stringify(exception)); 659} 660``` 661 662## accessibility.off('accessibilityStateChange') 663 664off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void 665 666Disables listening for the enabled status changes of the accessibility application. This API uses an asynchronous callback to return the result. 667 668**System capability**: SystemCapability.BarrierFree.Accessibility.Core 669 670**Parameters** 671 672| Name | Type | Mandatory | Description | 673| -------- | ----------------------- | ---- | ---------------------------------------- | 674| type | string | Yes | Type of the event to listen for, which is set to **'accessibilityStateChange'** in this API.| 675| callback | Callback<boolean> | No | Callback for the event. | 676 677**Example** 678 679```ts 680import accessibility from '@ohos.accessibility'; 681 682try { 683 accessibility.off('accessibilityStateChange', (data: boolean) => { 684 console.info('Unsubscribe accessibility state change, result: ' + JSON.stringify(data)); 685 }); 686} catch (exception) { 687 console.error('failed to Unsubscribe accessibility state change, because ' + JSON.stringify(exception)); 688} 689``` 690 691## accessibility.off('touchGuideStateChange') 692 693off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void 694 695Disables listening for the enabled status changes of the touch guide mode. This API uses an asynchronous callback to return the result. 696 697**System capability**: SystemCapability.BarrierFree.Accessibility.Core 698 699**Parameters** 700 701| Name | Type | Mandatory | Description | 702| -------- | ----------------------- | ---- | ---------------------------------------- | 703| type | string | Yes | Type of the event to listen for, which is set to **'touchGuideStateChange'** in this API.| 704| callback | Callback<boolean> | No | Callback for the event. | 705 706**Example** 707 708```ts 709import accessibility from '@ohos.accessibility'; 710 711try { 712 accessibility.off('touchGuideStateChange', (data: boolean) => { 713 console.info('Unsubscribe touch guide state change, result: ' + JSON.stringify(data)); 714 }); 715} catch (exception) { 716 console.error('failed to Unsubscribe touch guide state change, because ' + JSON.stringify(exception)); 717} 718``` 719 720## accessibility.isOpenAccessibility 721 722isOpenAccessibility(): Promise<boolean> 723 724Checks whether accessibility is enabled. This API uses a promise to return the result. 725 726**System capability**: SystemCapability.BarrierFree.Accessibility.Core 727 728**Return value** 729 730| Type | Description | 731| ---------------------- | ---------------------------------------- | 732| Promise<boolean> | Promise used to return the result. Returns **true** if accessibility is enabled; returns **false** otherwise.| 733 734**Example** 735 736```ts 737import accessibility from '@ohos.accessibility'; 738 739accessibility.isOpenAccessibility().then((data: boolean) => { 740 console.info('success data:isOpenAccessibility : ' + JSON.stringify(data)) 741}).catch((err: object) => { 742 console.error('failed to isOpenAccessibility because ' + JSON.stringify(err)); 743}); 744``` 745 746## accessibility.isOpenAccessibility 747 748isOpenAccessibility(callback: AsyncCallback<boolean>): void 749 750Checks whether accessibility is enabled. This API uses an asynchronous callback to return the result. 751 752**System capability**: SystemCapability.BarrierFree.Accessibility.Core 753 754**Parameters** 755 756| Name | Type | Mandatory | Description | 757| -------- | ---------------------------- | ---- | ----------------------------------- | 758| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. Returns **true** if accessibility is enabled; returns **false** otherwise.| 759 760**Example** 761 762```ts 763import accessibility from '@ohos.accessibility'; 764import { BusinessError } from '@ohos.base'; 765 766accessibility.isOpenAccessibility((err: BusinessError<void>, data: boolean) => { 767 if (err) { 768 console.error('failed to isOpenAccessibility because ' + JSON.stringify(err)); 769 return; 770 } 771 console.info('success data:isOpenAccessibility : ' + JSON.stringify(data)) 772}); 773``` 774 775## accessibility.isOpenTouchGuide 776 777isOpenTouchGuide(): Promise<boolean> 778 779Checks whether touch guide mode is enabled. This API uses a promise to return the result. 780 781**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 782 783**Return value** 784 785| Type | Description | 786| ---------------------- | ---------------------------------------- | 787| Promise<boolean> | Promise used to return the result. Returns **true** if touch guide mode is enabled; returns **false** otherwise.| 788 789**Example** 790 791```ts 792import accessibility from '@ohos.accessibility'; 793 794accessibility.isOpenTouchGuide().then((data: boolean) => { 795 console.info('success data:isOpenTouchGuide : ' + JSON.stringify(data)) 796}).catch((err: object) => { 797 console.error('failed to isOpenTouchGuide because ' + JSON.stringify(err)); 798}); 799``` 800 801## accessibility.isOpenTouchGuide 802 803isOpenTouchGuide(callback: AsyncCallback<boolean>): void 804 805Checks whether touch guide mode is enabled. This API uses an asynchronous callback to return the result. 806 807**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 808 809**Parameters** 810 811| Name | Type | Mandatory | Description | 812| -------- | ---------------------------- | ---- | ------------------------------------- | 813| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. Returns **true** if touch guide mode is enabled; returns **false** otherwise.| 814 815**Example** 816 817```ts 818import accessibility from '@ohos.accessibility'; 819import { BusinessError } from '@ohos.base'; 820 821accessibility.isOpenTouchGuide((err: BusinessError<void>, data: boolean) => { 822 if (err) { 823 console.error('failed to isOpenTouchGuide because ' + JSON.stringify(err)); 824 return; 825 } 826 console.info('success data:isOpenTouchGuide : ' + JSON.stringify(data)) 827}); 828``` 829 830## accessibility.sendEvent<sup>(deprecated)</sup> 831 832sendEvent(event: EventInfo): Promise<void> 833 834Sends an accessibility event. This API uses a promise to return the result. 835 836> **NOTE** 837> 838> This API is supported since API version 7 and deprecated since API version 9. 839> You are advised to use **[sendAccessibilityEvent()](#accessibilitysendaccessibilityevent9)**. 840 841**System capability**: SystemCapability.BarrierFree.Accessibility.Core 842 843**Parameters** 844 845| Name | Type | Mandatory | Description | 846| ----- | ----------------------- | ---- | -------- | 847| event | [EventInfo](#eventinfo) | Yes | Accessibility event.| 848 849**Return value** 850 851| Type | Description | 852| ------------------- | ---------------- | 853| Promise<void> | Promise that returns no value.| 854 855**Example** 856 857```ts 858import accessibility from '@ohos.accessibility'; 859 860let eventInfo: accessibility.EventInfo = ({ 861 type: 'click', 862 bundleName: 'com.example.MyApplication', 863 triggerAction: 'click' 864}); 865accessibility.sendEvent(eventInfo).then(() => { 866 console.info('send event success'); 867}).catch((err: object) => { 868 console.error('failed to sendEvent because ' + JSON.stringify(err)); 869}); 870``` 871 872## accessibility.sendEvent<sup>(deprecated)</sup> 873 874sendEvent(event: EventInfo, callback: AsyncCallback<void>): void 875 876Sends an accessibility event. This API uses an asynchronous callback to return the result. 877 878> **NOTE** 879> 880> This API is supported since API version 7 and deprecated since API version 9. 881> You are advised to use **[sendAccessibilityEvent()](#accessibilitysendaccessibilityevent9-1)**. 882 883**System capability**: SystemCapability.BarrierFree.Accessibility.Core 884 885**Parameters** 886 887| Name | Type | Mandatory | Description | 888| -------- | ------------------------- | ---- | ---------------------------------------- | 889| event | [EventInfo](#eventinfo) | Yes | Accessibility event. | 890| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, **error** that contains data is returned.| 891 892**Example** 893 894```ts 895import accessibility from '@ohos.accessibility'; 896import { BusinessError } from '@ohos.base'; 897 898let eventInfo: accessibility.EventInfo = ({ 899 type: 'click', 900 bundleName: 'com.example.MyApplication', 901 triggerAction: 'click' 902}); 903accessibility.sendEvent(eventInfo, (err: BusinessError<void>) => { 904 if (err) { 905 console.error('failed to sendEvent because ' + JSON.stringify(err)); 906 return; 907 } 908 console.info('sendEvent success'); 909}); 910``` 911 912## accessibility.sendAccessibilityEvent<sup>9+</sup> 913 914sendAccessibilityEvent(event: EventInfo): Promise<void> 915 916Sends an accessibility event. This API uses a promise to return the result. 917 918**System capability**: SystemCapability.BarrierFree.Accessibility.Core 919 920**Parameters** 921 922| Name | Type | Mandatory | Description | 923| ----- | ----------------------- | ---- | -------- | 924| event | [EventInfo](#eventinfo) | Yes | Accessibility event.| 925 926**Return value** 927 928| Type | Description | 929| ------------------- | ---------------- | 930| Promise<void> | Promise that returns no value.| 931 932**Example** 933 934```ts 935import accessibility from '@ohos.accessibility'; 936 937let eventInfo: accessibility.EventInfo = ({ 938 type: 'click', 939 bundleName: 'com.example.MyApplication', 940 triggerAction: 'click' 941}); 942try { 943 accessibility.sendAccessibilityEvent(eventInfo).then(() => { 944 console.info('send event success'); 945 }).catch((err: object) => { 946 console.error('failed to send event because ' + JSON.stringify(err)); 947 }); 948} catch (exception) { 949 console.error('failed to send event because ' + JSON.stringify(exception)); 950} 951``` 952 953## accessibility.sendAccessibilityEvent<sup>9+</sup> 954 955sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback<void>): void 956 957Sends an accessibility event. This API uses an asynchronous callback to return the result. 958 959**System capability**: SystemCapability.BarrierFree.Accessibility.Core 960 961**Parameters** 962 963| Name | Type | Mandatory | Description | 964| -------- | ------------------------- | ---- | ---------------------------------------- | 965| event | [EventInfo](#eventinfo) | Yes | Accessibility event. | 966| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, **error** that contains data is returned.| 967 968**Example** 969 970```ts 971import accessibility from '@ohos.accessibility'; 972import { BusinessError } from '@ohos.base'; 973 974let eventInfo: accessibility.EventInfo = ({ 975 type: 'click', 976 bundleName: 'com.example.MyApplication', 977 triggerAction: 'click' 978}); 979try { 980 accessibility.sendEvent(eventInfo, (err: BusinessError<void>) => { 981 if (err) { 982 console.error('failed to send event because ' + JSON.stringify(err)); 983 return; 984 } 985 console.info('send event success'); 986 }); 987} catch (exception) { 988 console.error('failed to send event because ' + JSON.stringify(exception)); 989} 990``` 991