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 '@kit.AccessibilityKit'; 13``` 14 15## AbilityState 16 17type AbilityState = 'enable' | 'disable' | 'install' 18 19Enumerates the states of an accessibility application. 20 21**System capability**: SystemCapability.BarrierFree.Accessibility.Core 22 23| Type | Description | 24| ------- | -------- | 25| 'enable' | The accessibility application is enabled.| 26| 'disable' | The accessibility application is disabled.| 27| 'install' | The accessibility application has been installed.| 28 29## AbilityType 30 31Enumerates the types of accessibility applications. 32 33**System capability**: SystemCapability.BarrierFree.Accessibility.Core 34 35| Name | Description | 36| ---------------- | --------- | 37| audible | The accessibility application provides audible feedback.| 38| generic | The accessibility application provides generic feedback.| 39| haptic | The accessibility application provides haptic feedback.| 40| spoken | The accessibility application provides spoken feedback.| 41| visual | The accessibility application provides visual feedback.| 42| all<sup>9+</sup> | All the preceding types.| 43 44## AccessibilityAbilityInfo 45 46Provides information about an accessibility application. 47 48**System capability**: SystemCapability.BarrierFree.Accessibility.Core 49 50### Properties 51 52| Name | Type | Readable | Writable | Description | 53| ------------------------------ | ---------------------------------------- | ---- | ---- | ---------------- | 54| id | string | Yes | No | Ability ID.| 55| name | string | Yes | No | Ability name. | 56| bundleName | string | Yes | No | Bundle name. | 57| targetBundleNames<sup>9+</sup> | Array<string> | Yes | No | Name of the target bundle. | 58| abilityTypes | Array<[AbilityType](#abilitytype)> | Yes | No | Accessibility application type. | 59| capabilities | Array<[Capability](#capability)> | Yes | No | Capabilities list of the accessibility application. | 60| description | string | Yes | No | Description of the accessibility application. | 61| eventTypes | Array<[EventType](#eventtype)> | Yes | No | List of events that the accessibility application focuses on. | 62| needHide<sup>12+</sup> | boolean | Yes | No | Whether the auxiliary application is hidden in the list of installed extended services. The value **true** means the auxiliary application is hidden, and the value **false** means the opposite. | 63| label<sup>12+</sup> | string | Yes | No | Name of the application in the extended service list. | 64 65## Action 66 67type Action = 'accessibilityFocus' | 'clearAccessibilityFocus' | 'focus' | 'clearFocus' | 'clearSelection' | 68 'click' | 'longClick' | 'cut' | 'copy' | 'paste' | 'select' | 'setText' | 'delete' | 69 'scrollForward' | 'scrollBackward' | 'setSelection' | 'setCursorPosition' | 'home' | 70 'back' | 'recentTask' | 'notificationCenter' | 'controlCenter' | 'common' 71 72Target actions supported by the application. The target actions for which parameters need to be set have been specified in the description of the following table. 73 74**System capability**: SystemCapability.BarrierFree.Accessibility.Core 75 76| Type | Description | 77| ----------------------- |--------------------| 78| 'click' | Clicking. | 79| 'longClick' | Long pressing. | 80| 'scrollForward' | Scrolling forward.| 81| 'scrollBackward' | Scrolling backward.| 82| 'focus' | Obtaining the focus.| 83| 'clearFocus' | Clearing focus.| 84| 'clearSelection' | Clearing selection. Not supported yet.| 85| 'accessibilityFocus' | Obtaining the accessibility focus. | 86| 'clearAccessibilityFocus' | Clearing the accessibility focus. | 87| 'cut' | Cutting. | 88| 'copy' | Copying. | 89| 'paste' | Pasting. | 90| 'select' | Selecting. | 91| 'setText' | Setting text. You need to set the **setText** parameter.| 92| 'delete' | Delete. Not supported yet. | 93| 'setSelection' | Selecting. You need to set the **selectTextBegin**, **selectTextEnd** and **selectTextInForWard** parameters. | 94| 'common' | Common actions used in auto-focusing and auto-broadcasting. | 95| 'home' | Returning to the home screen. | 96| 'back' | Returning to the previous screen. | 97| 'recentTask' | Opening a recent task. | 98| 'notificationCenter' | Opening the notification bar. | 99| 'controlCenter' | Opening the control center. | 100| 'setCursorPosition' | Setting cursor location. You need to set the **offset** parameter. | 101 102## Capability 103 104type Capability = 'retrieve' | 'touchGuide' | 'keyEventObserver' | 'zoom' | 'gesture' 105 106Enumerates the capabilities of an accessibility application. 107 108**System capability**: SystemCapability.BarrierFree.Accessibility.Core 109 110| Type | Description | 111| ---------------- |-----------------------| 112| 'retrieve' | Capability to retrieve the window content. | 113| 'touchGuide' | Capability of touch guide mode. | 114| 'keyEventObserver' | Capability to filter key events. | 115| 'zoom' | Capability to control the display zoom level. Not supported currently.| 116| 'gesture' | Capability to perform gesture actions. | 117 118## CaptionsFontEdgeType<sup>8+</sup> 119 120type CaptionsFontEdgeType = 'none' | 'raised' | 'depressed' | 'uniform' | 'dropShadow' 121 122Enumerates the font edge types of captions. 123 124**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 125 126| Type | Description | 127| ---------- | ----- | 128| 'none' | No effect. | 129| 'raised' | Raised effect.| 130| 'depressed' | Depressed effect.| 131| 'uniform' | Uniform effect.| 132| 'dropShadow' | Drop shadow effect.| 133 134## CaptionsFontFamily<sup>8+</sup> 135 136type CaptionsFontFamily = 'default' | 'monospacedSerif' | 'serif' | 'monospacedSansSerif' | 137 'sansSerif' | 'casual' | 'cursive' | 'smallCapitals' 138 139Enumerates the font families of captions. 140 141**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 142 143| Name | Description | 144| ------------------- | ----------------- | 145| 'default' | Default font family. | 146| 'monospacedSerif' | Monospaced Serif fonts, which use the same width for each character. | 147| 'serif' | Serif fonts. | 148| 'monospacedSansSerif' | Monospaced Sans Serif fonts, which use the same width for each character.| 149| 'sansSerif' | Sans Serif fonts. | 150| 'casual' | Casual fonts. | 151| 'cursive' | Cursive fonts. | 152| 'smallCapitals' | Small caps fonts. | 153 154## CaptionsStyle<sup>8+</sup> 155 156Describes the style of captions. 157 158**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 159 160| Name | Type | Readable | Writable | Description | 161| --------------- | ---------------------------------------- | ---- | ---- | ----------- | 162| fontFamily | [CaptionsFontFamily](#captionsfontfamily8) | Yes | No | Font family of captions. | 163| fontScale | number | Yes | No | Font scale factor of captions, in percentage. The value ranges from 1 to 200.| 164| fontColor | number \| string | Yes | No | Font color of captions. For example, red corresponds to #FF0000. | 165| fontEdgeType | [CaptionsFontEdgeType](#captionsfontedgetype8) | Yes | No | Font edge type of captions. | 166| backgroundColor | number \| string | Yes | No | Background color of captions. For example, red corresponds to #FF0000. | 167| windowColor | number \| string | Yes | No | Window color of captions. For example, red corresponds to #FF0000. | 168 169## CaptionsManager<sup>8+</sup> 170 171Implements configuration management for captions. Before calling any API of **CaptionsManager**, you must use the [accessibility.getCaptionsManager()](#accessibilitygetcaptionsmanagerdeprecated) API to obtain a **CaptionsManager** instance. 172 173**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 174 175### Properties 176 177| Name | Type | Readable | Writable | Description | 178| ------- | -------------------------------- | ---- | ---- | ----------- | 179| enabled | boolean | Yes | No | Whether to enable captions configuration.| 180| style | [CaptionsStyle](#captionsstyle8) | Yes | No | Style of captions. | 181 182For a boolean return value, **True** means that the feature is enabled, and **False** means the opposite. 183 184### on('enableChange')<sup>(deprecated)</sup> 185 186on(type: 'enableChange', callback: Callback<boolean>): void; 187 188Enables listening for the enabled status changes of captions configuration. This API uses an asynchronous callback to return the result. 189 190> **NOTE** 191> 192> This API is deprecated since API version 12. 193 194**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 195 196**Parameters** 197 198| Name | Type | Mandatory | Description | 199| -------- | ----------------------- | ---- | --------------------------------------- | 200| type | string | Yes | Listening type, which is set to **'enableChange'** in this API.| 201| callback | Callback<boolean> | Yes | Callback invoked when the enabled status of captions configuration changes. | 202 203**Error codes** 204 205For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 206 207| ID| Error Message| 208| ------- | -------------------------------- | 209| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 210 211**Example** 212 213```ts 214import { accessibility } from '@kit.AccessibilityKit'; 215 216let captionsManager = accessibility.getCaptionsManager(); 217captionsManager.on('enableChange', (data: boolean) => { 218 console.info(`subscribe caption manager enable state change, result: ${JSON.stringify(data)}`); 219}) 220``` 221 222### on('styleChange')<sup>(deprecated)</sup> 223 224on(type: 'styleChange', callback: Callback<CaptionsStyle>): void; 225 226Enables listening for captions style changes. This API uses an asynchronous callback to return the result. 227 228> **NOTE** 229> 230> This API is deprecated since API version 12. 231 232**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 233 234**Parameters** 235 236| Name | Type | Mandatory | Description | 237| -------- | ---------------------------------------- | ---- | ---------------------------------- | 238| type | string | Yes | Listening type, which is set to **'styleChange'** in this API.| 239| callback | Callback<[CaptionsStyle](#captionsstyle8)> | Yes | Callback invoked when the style of captions changes. | 240 241**Error codes** 242 243For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 244 245| ID| Error Message| 246| ------- | -------------------------------- | 247| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 248 249**Example** 250 251```ts 252import { accessibility } from '@kit.AccessibilityKit'; 253 254let captionsManager = accessibility.getCaptionsManager(); 255 256captionsManager.on('styleChange', (data: accessibility.CaptionsStyle) => { 257 console.info(`subscribe caption manager style state change, result: ${JSON.stringify(data)}`); 258}); 259``` 260 261### off('enableChange')<sup>(deprecated)</sup> 262 263off(type: 'enableChange', callback?: Callback<boolean>): void; 264 265Disables listening for the enabled status changes of captions configuration. This API uses an asynchronous callback to return the result. 266 267> **NOTE** 268> 269> This API is deprecated since API version 12. 270 271**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 272 273**Parameters** 274 275| Name | Type | Mandatory| Description | 276| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 277| type | string | Yes | Listening type, which is set to **'enableChange'** in this API.| 278| callback | Callback<boolean> | No | Callback used for disable listening. The value must be the same as the value of **callback** in **on('enableChange')**. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 279 280**Error codes** 281 282For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 283 284| ID| Error Message| 285| ------- | -------------------------------- | 286| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 287 288**Example** 289 290```ts 291import { accessibility } from '@kit.AccessibilityKit'; 292 293let captionsManager = accessibility.getCaptionsManager(); 294 295captionsManager.off('enableChange', (data: boolean) => { 296 console.info(`Unsubscribe caption manager enable state change, result: ${JSON.stringify(data)}`); 297}); 298``` 299 300### off('styleChange')<sup>(deprecated)</sup> 301 302off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void; 303 304Disables listening for captions style changes. This API uses an asynchronous callback to return the result. 305 306> **NOTE** 307> 308> This API is deprecated since API version 12. 309 310**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 311 312**Parameters** 313 314| Name | Type | Mandatory| Description | 315| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | 316| type | string | Yes | Listening type, which is set to **'styleChange'** in this API. | 317| callback | Callback<[CaptionsStyle](#captionsstyle8)> | No | Callback used for disable listening. The value must be the same as the value of **callback** in **on('styleChange')**. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 318 319**Error codes** 320 321For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 322 323| ID| Error Message| 324| ------- | -------------------------------- | 325| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 326 327**Example** 328 329```ts 330import { accessibility } from '@kit.AccessibilityKit'; 331 332let captionsManager = accessibility.getCaptionsManager(); 333 334captionsManager.off('styleChange', (data: accessibility.CaptionsStyle) => { 335 console.info(`Unsubscribe caption manager style state change, result: ${JSON.stringify(data)}`); 336}); 337``` 338 339## EventInfo 340 341Describes a GUI change event. 342 343**System capability**: SystemCapability.BarrierFree.Accessibility.Core 344 345### Properties 346 347| Name | Type | Mandatory | Description | 348| ---------------- | ------------------------------------- |-----|-----------------------| 349| type | [EventType](#eventtype) | Yes | Accessibility event type. | 350| windowUpdateType | [WindowUpdateType](#windowupdatetype) | No | Window update type. | 351| bundleName | string | Yes | Name of the target application. | 352| componentType | string | No | Type of the event source component, for example, button or chart. | 353| pageId | number | No | Page ID of the event source. | 354| description | string | No | Event description. | 355| triggerAction | [Action](#action) | Yes | Action that triggers the event. | 356| textMoveUnit | [TextMoveUnit](#textmoveunit) | No | Text move granularity. | 357| contents | Array<string> | No | Array of contents. | 358| lastContent | string | No | Latest content. | 359| beginIndex | number | No | Sequence number of the first item displayed on the page.| 360| currentIndex | number | No | Sequence number of the current item. | 361| endIndex | number | No | Sequence number of the last item displayed on the page.| 362| itemCount | number | No | Total number of records. | 363| elementId<sup>12+</sup> | number | No | Element ID of the component. | 364| textAnnouncedForAccessibility<sup>12+</sup> | string | No | Content for auto-broadcasting. | 365| textResourceAnnouncedForAccessibility<sup>18+</sup> | Resource | No | Content for auto-broadcasting, which supports resources of the string type. | 366| customId<sup>12+</sup> | string | No | Component ID for auto-focusing. | 367 368### constructor 369 370constructor(jsonObject) 371 372Implements a constructor. 373 374**System capability**: SystemCapability.BarrierFree.Accessibility.Core 375 376**Parameters** 377 378| Name | Type | Mandatory | Description | 379| ---------- | ------ | ---- | -------------------- | 380| jsonObject | string | Yes | JSON string required for creating an object.| 381 382**Example** 383 384 ```ts 385 import { accessibility } from '@kit.AccessibilityKit'; 386 387 let eventInfo: accessibility.EventInfo = ({ 388 type: 'click', 389 bundleName: 'com.example.MyApplication', 390 triggerAction: 'click', 391 }); 392 ``` 393 394### constructor<sup>11+</sup> 395 396constructor(type: EventType, bundleName: string, triggerAction: Action) 397 398Implements a constructor. 399 400**System capability**: SystemCapability.BarrierFree.Accessibility.Core 401 402**Parameters** 403 404| Name | Type | Mandatory| Description | 405|------|-------------------|---|---------------| 406| type | [EventType](#eventtype) | Yes| Accessibility event types. | 407| bundleName | string | Yes| Target application name. | 408| triggerAction | [Action](#action) | Yes| Action that triggers the event.| 409 410**Example** 411 412 ```ts 413 import { accessibility } from '@kit.AccessibilityKit'; 414 415 let eventInfo = new accessibility.EventInfo('click', 'com.example.MyApplication', 'click'); 416 ``` 417 418## EventType 419 420type EventType = 'accessibilityFocus' | 'accessibilityFocusClear' | 421'click' | 'longClick' | 'focus' | 'select' | 'hoverEnter' | 'hoverExit' | 422'textUpdate' | 'textSelectionUpdate' | 'scroll' | 'requestFocusForAccessibility' | 423'announceForAccessibility' | 'requestFocusForAccessibilityNotInterrupt' | 424'announceForAccessibilityNotInterrupt' | 'scrolling' 425 426Enumerates accessibility event types. 427 428**System capability**: SystemCapability.BarrierFree.Accessibility.Core 429 430| Type | Description | 431| ----------------------- |------------------------| 432| 'accessibilityFocus' | Event indicating that the accessibility focus is obtained. | 433| 'accessibilityFocusClear' | Event indicating that the accessibility focus is cleared. | 434| 'click' | Event of clicking a component. | 435| 'longClick' | Event indicating that the component is long pressed. | 436| 'select' | Event of selecting a component. | 437| 'hoverEnter' | Event indicating that the hover enters a component. | 438| 'hoverExit' | Event indicating that the hover exits a component. | 439| 'focus' | Event indicating that the component obtains the focus. Not supported currently. | 440| 'textUpdate' | Event indicating that the component text has been updated.| 441| 'textSelectionUpdate' | Event indicating that the selected text has been updated. Not supported currently.| 442| 'scroll' | Event of the scroll view. | 443| 'requestFocusForAccessibility' | Event of the auto-focusing.| 444| 'announceForAccessibility' | Event of the auto-broadcasting.| 445| 'requestFocusForAccessibilityNotInterrupt' | Event of the auto-focusing without interruption.<br>This event is supported since API version 18.| 446| 'announceForAccessibilityNotInterrupt' | Event of the auto-broadcasting without interruption.<br>This event is supported since API version 18.| 447| 'scrolling' | Event indicating that an item is scrolled out of the screen in the scrolling view.<br>This event is supported since API version 18.| 448 449## TextMoveUnit 450 451type TextMoveUnit = 'char' | 'word' | 'line' | 'page' | 'paragraph' 452 453Enumerates the movement units for traversing the node text. 454 455**System capability**: SystemCapability.BarrierFree.Accessibility.Core 456 457| Type | Description | 458| --------- | --------------- | 459| 'char' | The movement unit for traversing the node text is by character.| 460| 'word' | The movement unit for traversing the node text is by word. | 461| 'line' | The movement unit for traversing the node text is by line. | 462| 'page' | The movement unit for traversing the node text is by page. | 463| 'paragraph' | The movement unit for traversing the node text is by paragraph.| 464 465## WindowUpdateType 466 467type WindowUpdateType = 'add' | 'remove' | 'bounds' | 'active' | 'focus' 468 469Enumerates window update types. 470 471**System capability**: SystemCapability.BarrierFree.Accessibility.Core 472 473| Type | Description | 474| ------ | ------------------ | 475| 'add' | Window adding. | 476| 'remove' | Window deletion. | 477| 'bounds' | Window boundary change. | 478| 'active' | Window activity change.| 479| 'focus' | Window focus change. | 480 481## accessibility.getAbilityLists<sup>(deprecated)</sup> 482 483getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>> 484 485Obtains the accessibility application list. This API uses a promise to return the result. 486 487> **NOTE** 488> 489> This API is supported since API version 7 and deprecated since API version 9. 490> You are advised to use [accessibility.getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9) instead. 491 492**System capability**: SystemCapability.BarrierFree.Accessibility.Core 493 494**Parameters** 495 496| Name | Type | Mandatory | Description | 497| ----------- | ----------------------------- | ---- | -------- | 498| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type.| 499| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status.| 500 501**Return value** 502 503| Type | Description | 504| ---------------------------------------- | --------------------- | 505| Promise<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Promise used to return the accessibility application list.| 506 507**Example** 508 509```ts 510import { accessibility } from '@kit.AccessibilityKit'; 511import { BusinessError } from '@kit.BasicServicesKit'; 512 513let abilityType: accessibility.AbilityType = 'spoken'; 514let abilityState: accessibility.AbilityState = 'enable'; 515 516accessibility.getAbilityLists(abilityType, abilityState).then((data: accessibility.AccessibilityAbilityInfo[]) => { 517 console.info(`Succeeded in get accessibility extension list, ${JSON.stringify(data)}`); 518}).catch((err: BusinessError) => { 519 console.error(`failed to get accessibility extension list because ${JSON.stringify(err)}`); 520}); 521``` 522 523## accessibility.getAbilityLists<sup>(deprecated)</sup> 524 525getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void 526 527Obtains the accessibility application list. This API uses an asynchronous callback to return the result. 528 529> **NOTE** 530> 531> This API is supported since API version 7 and deprecated since API version 9. 532> You are advised to use [accessibility.getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9-1) instead. 533 534**System capability**: SystemCapability.BarrierFree.Accessibility.Core 535 536**Parameters** 537 538| Name | Type | Mandatory | Description | 539| ----------- | ---------------------------------------- | ---- | ---------------- | 540| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type. | 541| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status. | 542| callback | AsyncCallback<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Yes | Callback used to return the accessibility application list.| 543 544**Example** 545 546```ts 547import { accessibility } from '@kit.AccessibilityKit'; 548import { BusinessError } from '@kit.BasicServicesKit'; 549 550let abilityType: accessibility.AbilityType = 'spoken'; 551let abilityState: accessibility.AbilityState = 'enable'; 552 553accessibility.getAbilityLists(abilityType, abilityState, (err: BusinessError, data: accessibility.AccessibilityAbilityInfo[]) => { 554 if (err) { 555 console.error(`failed to get accessibility extension list because ${JSON.stringify(err)}`); 556 return; 557 } 558 console.info(`Succeeded in get accessibility extension list, ${JSON.stringify(data)}`); 559}) 560``` 561 562## accessibility.getAccessibilityExtensionList<sup>9+</sup> 563 564getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState): Promise<Array<AccessibilityAbilityInfo>> 565 566Obtains the accessibility application list. This API uses a promise to return the result. 567 568**System capability**: SystemCapability.BarrierFree.Accessibility.Core 569 570**Parameters** 571 572| Name | Type | Mandatory | Description | 573| ----------- | ----------------------------- | ---- | -------- | 574| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type.| 575| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status.| 576 577**Return value** 578 579| Type | Description | 580| ---------------------------------------- | --------------------- | 581| Promise<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Promise used to return the accessibility application list.| 582 583**Error codes** 584 585For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 586 587| ID| Error Message| 588| ------- | -------------------------------- | 589| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 590 591**Example** 592 593```ts 594import { accessibility } from '@kit.AccessibilityKit'; 595import { BusinessError } from '@kit.BasicServicesKit'; 596 597let abilityType: accessibility.AbilityType = 'spoken'; 598let abilityState: accessibility.AbilityState = 'enable'; 599 600accessibility.getAccessibilityExtensionList(abilityType, abilityState).then((data: accessibility.AccessibilityAbilityInfo[]) => { 601 console.info(`Succeeded in get accessibility extension list, ${JSON.stringify(data)}`); 602}).catch((err: BusinessError) => { 603 console.error(`failed to get accessibility extension list, Code is ${err.code}, message is ${err.message}`); 604}); 605``` 606 607## accessibility.getAccessibilityExtensionList<sup>9+</sup> 608 609getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState, callback: AsyncCallback<Array<AccessibilityAbilityInfo>>): void 610 611Obtains the accessibility application list. This API uses an asynchronous callback to return the result. 612 613**System capability**: SystemCapability.BarrierFree.Accessibility.Core 614 615**Parameters** 616 617| Name | Type | Mandatory | Description | 618| ----------- | ---------------------------------------- | ---- | ---------------- | 619| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type. | 620| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status. | 621| callback | AsyncCallback<Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)>> | Yes | Callback used to return the accessibility application list.| 622 623**Error codes** 624 625For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 626 627| ID| Error Message| 628| ------- | -------------------------------- | 629| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 630 631**Example** 632 633```ts 634import { accessibility } from '@kit.AccessibilityKit'; 635import { BusinessError } from '@kit.BasicServicesKit'; 636 637let abilityType: accessibility.AbilityType = 'spoken'; 638let abilityState: accessibility.AbilityState = 'enable'; 639 640accessibility.getAccessibilityExtensionList(abilityType, abilityState,(err: BusinessError, data: accessibility.AccessibilityAbilityInfo[]) => { 641 if (err) { 642 console.error(`failed to get accessibility extension list, Code is ${err.code}, message is ${err.message}`); 643 return; 644 } 645 console.info(`Succeeded in get accessibility extension list, ${JSON.stringify(data)}`); 646}); 647``` 648 649## accessibility.getAccessibilityExtensionListSync<sup>12+</sup> 650 651getAccessibilityExtensionListSync(abilityType: AbilityType, stateType: AbilityState): Array<AccessibilityAbilityInfo> 652 653Obtains the API for synchronizing the accessibility application list. 654 655**System capability**: SystemCapability.BarrierFree.Accessibility.Core 656 657**Parameters** 658 659| Name | Type | Mandatory | Description | 660| ----------- | ----------------------------- | ---- | -------- | 661| abilityType | [AbilityType](#abilitytype) | Yes | Accessibility application type.| 662| stateType | [AbilityState](#abilitystate) | Yes | Accessibility application status.| 663 664**Return value** 665 666| Type | Description | 667| ---------------------------------------- | --------------------- | 668| Array<[AccessibilityAbilityInfo](#accessibilityabilityinfo)> | Promise used to return the accessibility application list.| 669 670**Example** 671 672```ts 673import { accessibility } from '@kit.AccessibilityKit'; 674import { BusinessError } from '@kit.BasicServicesKit'; 675 676let abilityType: accessibility.AbilityType = 'all'; 677let abilityState: accessibility.AbilityState = 'install'; 678let data: accessibility.AccessibilityAbilityInfo[]; 679 680try { 681 data = accessibility.getAccessibilityExtensionListSync(abilityType, abilityState); 682 console.info(`Succeeded in get accessibility extension list, ${JSON.stringify(data)}`); 683} catch (error) { 684 let err = error as BusinessError; 685 console.error(`error code: ${err.code}`); 686} 687``` 688 689## accessibility.getCaptionsManager<sup>(deprecated)</sup> 690 691getCaptionsManager(): CaptionsManager 692 693Obtains a **CaptionsManager** instance. 694 695> **NOTE** 696> 697> This API is deprecated since API version 12. 698 699**System capability**: SystemCapability.BarrierFree.Accessibility.Hearing 700 701**Return value** 702 703| Type | Description | 704| ------------------------------------ | ---------- | 705| [CaptionsManager](#captionsmanager8) | Captions configuration.| 706 707**Example** 708 709```ts 710import { accessibility } from '@kit.AccessibilityKit'; 711 712let captionsManager = accessibility.getCaptionsManager(); 713``` 714 715## accessibility.on('accessibilityStateChange') 716 717on(type: 'accessibilityStateChange', callback: Callback<boolean>): void 718 719Enables listening for the enabled status changes of the accessibility application. This API uses an asynchronous callback to return the result. 720 721**System capability**: SystemCapability.BarrierFree.Accessibility.Core 722 723**Parameters** 724 725| Name | Type | Mandatory| Description | 726| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 727| type | string | Yes | Listening type, which is set to **'accessibilityStateChange'** in this API.| 728| callback | Callback<boolean> | Yes | Callback invoked when the enabled status of accessibility application changes. The returned result indicates the global enabled status of the accessibility application.| 729 730**Error codes** 731 732For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 733 734| ID| Error Message| 735| ------- | -------------------------------- | 736| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 737 738**Example** 739 740```ts 741import { accessibility } from '@kit.AccessibilityKit'; 742 743accessibility.on('accessibilityStateChange', (data: boolean) => { 744 console.info(`subscribe accessibility state change, result: ${JSON.stringify(data)}`); 745}); 746``` 747 748## accessibility.on('touchGuideStateChange') 749 750on(type: 'touchGuideStateChange', callback: Callback<boolean>): void 751 752Enables listening for the enabled status changes of the touch guide mode. This API uses an asynchronous callback to return the result. 753 754**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 755 756**Parameters** 757 758| Name | Type | Mandatory | Description | 759| -------- | ----------------------- | ---- | ---------------------------------------- | 760| type | string | Yes | Listening type, which is set to **'touchGuideStateChange'** in this API.| 761| callback | Callback<boolean> | Yes | Callback invoked when the enabled status of touch guide mode changes. | 762 763**Error codes** 764 765For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 766 767| ID| Error Message| 768| ------- | -------------------------------- | 769| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 770 771**Example** 772 773```ts 774import { accessibility } from '@kit.AccessibilityKit'; 775 776accessibility.on('touchGuideStateChange', (data: boolean) => { 777 console.info(`subscribe touch guide state change, result: ${JSON.stringify(data)}`); 778}); 779``` 780 781## accessibility.on('screenReaderStateChange')<sup>18+</sup> 782 783on(type: 'screenReaderStateChange', callback: Callback<boolean>): void 784 785Enables listening for the enabled status changes of the screen reader. This API uses an asynchronous callback to return the result. 786 787**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 788 789**Parameters** 790 791| Name | Type | Mandatory | Description | 792| -------- | ----------------------- | ---- | ---------------------------------------- | 793| type | string | Yes | Listening type, which is set to **'screenReaderStateChange'** in this API.| 794| callback | Callback<boolean> | Yes | Callback invoked when the enabled status of screen reader changes. | 795 796**Error codes** 797 798For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 799 800| ID| Error Message| 801| ------- | -------------------------------- | 802| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 803 804**Example** 805 806```ts 807import { accessibility } from '@kit.AccessibilityKit'; 808 809accessibility.on('screenReaderStateChange', (data: boolean) => { 810 console.info(`subscribe screen reader state change, result: ${JSON.stringify(data)}`); 811}); 812``` 813 814## accessibility.off('accessibilityStateChange') 815 816off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void 817 818Disables listening for the enabled status changes of the accessibility application. This API uses an asynchronous callback to return the result. 819 820**System capability**: SystemCapability.BarrierFree.Accessibility.Core 821 822**Parameters** 823 824| Name | Type | Mandatory| Description | 825| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 826| type | string | Yes | Listening type, which is set to **'accessibilityStateChange'** in this API.| 827| callback | Callback<boolean> | No | Callback used for disable listening. The value must be the same as the value of **callback** in **accessibility.on('accessibilityStateChange')**. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 828 829**Error codes** 830 831For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 832 833| ID| Error Message| 834| ------- | -------------------------------- | 835| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 836 837**Example** 838 839```ts 840import { accessibility } from '@kit.AccessibilityKit'; 841 842accessibility.off('accessibilityStateChange', (data: boolean) => { 843 console.info(`Unsubscribe accessibility state change, result: ${JSON.stringify(data)}`); 844}); 845``` 846 847## accessibility.off('touchGuideStateChange') 848 849off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void 850 851Disables listening for the enabled status changes of the touch guide mode. This API uses an asynchronous callback to return the result. 852 853**System capability**: SystemCapability.BarrierFree.Accessibility.Core 854 855**Parameters** 856 857| Name | Type | Mandatory| Description | 858| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 859| type | string | Yes | Listening type, which is set to **'touchGuideStateChange'** in this API.| 860| callback | Callback<boolean> | No | Callback used for disable listening. The value must be the same as the value of **callback** in **accessibility.on('touchGuideStateChange')**. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 861 862**Error codes** 863 864For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 865 866| ID| Error Message| 867| ------- | -------------------------------- | 868| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 869 870**Example** 871 872```ts 873import { accessibility } from '@kit.AccessibilityKit'; 874 875accessibility.off('touchGuideStateChange', (data: boolean) => { 876 console.info(`Unsubscribe touch guide state change, result: ${JSON.stringify(data)}`); 877}); 878``` 879 880## accessibility.off('screenReaderStateChange')<sup>18+</sup> 881 882off(type: 'screenReaderStateChange', callback?: Callback<boolean>): void 883 884Disables listening for the enabled status changes of the screen reader. This API uses an asynchronous callback to return the result. 885 886**System capability**: SystemCapability.BarrierFree.Accessibility.Core 887 888**Parameters** 889 890| Name | Type | Mandatory| Description | 891| -------- | ----------------------- | ---- | ------------------------------------------------------------ | 892| type | string | Yes | Listening type, which is set to **'screenReaderStateChange'** in this API.| 893| callback | Callback<boolean> | No | Callback used for disable listening. The value must be the same as the value of **callback** in **accessibility.on('screenReaderStateChange')**. If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.| 894 895**Error codes** 896 897For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 898 899| ID| Error Message| 900| ------- | -------------------------------- | 901| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 902 903**Example** 904 905```ts 906import { accessibility } from '@kit.AccessibilityKit'; 907 908accessibility.off('screenReaderStateChange', (data: boolean) => { 909 console.info(`Unsubscribe screen reader state change, result: ${JSON.stringify(data)}`); 910}); 911``` 912 913## accessibility.isOpenAccessibility<sup>(deprecated)</sup> 914 915isOpenAccessibility(): Promise<boolean> 916 917Checks whether accessibility is enabled. This API uses a promise to return the result. 918 919> **NOTE** 920> 921> This API is deprecated since API version 10. 922> 923> You are advised to use [accessibility.isOpenAccessibilitySync](#accessibilityisopenaccessibilitysync10) instead. 924 925**System capability**: SystemCapability.BarrierFree.Accessibility.Core 926 927**Return value** 928 929| Type | Description | 930| ---------------------- | ---------------------------------------- | 931| Promise<boolean> | Promise used to return the result. Returns **true** if accessibility is enabled; returns **false** otherwise.| 932 933**Example** 934 935```ts 936import { accessibility } from '@kit.AccessibilityKit'; 937import { BusinessError } from '@kit.BasicServicesKit'; 938 939accessibility.isOpenAccessibility().then((data: boolean) => { 940 console.info(`success data:isOpenAccessibility : ${JSON.stringify(data)}`) 941}).catch((err: BusinessError) => { 942 console.error(`failed to isOpenAccessibility, Code is ${err.code}, message is ${err.message}`); 943}); 944``` 945 946## accessibility.isOpenAccessibility<sup>(deprecated)</sup> 947 948isOpenAccessibility(callback: AsyncCallback<boolean>): void 949 950Checks whether accessibility is enabled. This API uses an asynchronous callback to return the result. 951 952> **NOTE** 953> 954> This API is deprecated since API version 10. 955> 956> You are advised to use [accessibility.isOpenAccessibilitySync](#accessibilityisopenaccessibilitysync10) instead. 957 958**System capability**: SystemCapability.BarrierFree.Accessibility.Core 959 960**Parameters** 961 962| Name | Type | Mandatory | Description | 963| -------- | ---------------------------- | ---- | ----------------------------------- | 964| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. Returns **true** if accessibility is enabled; returns **false** otherwise.| 965 966**Example** 967 968```ts 969import { accessibility } from '@kit.AccessibilityKit'; 970import { BusinessError } from '@kit.BasicServicesKit'; 971 972accessibility.isOpenAccessibility((err: BusinessError, data: boolean) => { 973 if (err) { 974 console.error(`failed to isOpenAccessibility, Code is ${err.code}, message is ${err.message}`); 975 return; 976 } 977 console.info(`success data:isOpenAccessibility : ${JSON.stringify(data)}`); 978}); 979``` 980 981## accessibility.isOpenAccessibilitySync<sup>10+</sup> 982 983isOpenAccessibilitySync(): boolean 984 985Checks whether accessibility is enabled. 986 987**Atomic service API**: This API can be used in atomic services since API version 11. 988 989**System capability**: SystemCapability.BarrierFree.Accessibility.Core 990 991**Return value** 992 993| Type | Description | 994| ----------- | ------------------------------------- | 995| boolean | Returns **true** if accessibility is enabled; returns **false** otherwise.| 996 997**Example** 998 999```ts 1000import { accessibility } from '@kit.AccessibilityKit'; 1001import { BusinessError } from '@kit.BasicServicesKit'; 1002 1003let status: boolean = accessibility.isOpenAccessibilitySync(); 1004``` 1005 1006## accessibility.isOpenTouchGuide<sup>(deprecated)</sup> 1007 1008isOpenTouchGuide(): Promise<boolean> 1009 1010Checks whether touch guide mode is enabled. This API uses a promise to return the result. 1011 1012> **NOTE** 1013> 1014> This API is deprecated since API version 10. 1015> 1016> You are advised to use [accessibility.isOpenTouchGuideSync](#accessibilityisopentouchguidesync10) instead. 1017 1018**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 1019 1020**Return value** 1021 1022| Type | Description | 1023| ---------------------- | ---------------------------------------- | 1024| Promise<boolean> | Promise used to return the result. Returns **true** if touch guide mode is enabled; returns **false** otherwise.| 1025 1026**Example** 1027 1028```ts 1029import { accessibility } from '@kit.AccessibilityKit'; 1030import { BusinessError } from '@kit.BasicServicesKit'; 1031 1032accessibility.isOpenTouchGuide().then((data: boolean) => { 1033 console.info(`success data:isOpenTouchGuide : ${JSON.stringify(data)}`); 1034}).catch((err: BusinessError) => { 1035 console.error(`failed to isOpenTouchGuide, Code is ${err.code}, message is ${err.message}`); 1036}); 1037``` 1038 1039## accessibility.isOpenTouchGuide<sup>(deprecated)</sup> 1040 1041isOpenTouchGuide(callback: AsyncCallback<boolean>): void 1042 1043Checks whether touch guide mode is enabled. This API uses an asynchronous callback to return the result. 1044 1045> **NOTE** 1046> 1047> This API is deprecated since API version 10. 1048> 1049> You are advised to use [accessibility.isOpenTouchGuideSync](#accessibilityisopentouchguidesync10) instead. 1050 1051**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 1052 1053**Parameters** 1054 1055| Name | Type | Mandatory | Description | 1056| -------- | ---------------------------- | ---- | ------------------------------------- | 1057| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. Returns **true** if touch guide mode is enabled; returns **false** otherwise.| 1058 1059**Example** 1060 1061```ts 1062import { accessibility } from '@kit.AccessibilityKit'; 1063import { BusinessError } from '@kit.BasicServicesKit'; 1064 1065accessibility.isOpenTouchGuide((err: BusinessError, data: boolean) => { 1066 if (err) { 1067 console.error(`failed to isOpenTouchGuide, Code is ${err.code}, message is ${err.message}`); 1068 return; 1069 } 1070 console.info(`success data:isOpenTouchGuide : ${JSON.stringify(data)}`); 1071}); 1072``` 1073 1074## accessibility.isOpenTouchGuideSync<sup>10+</sup> 1075 1076isOpenTouchGuideSync(): boolean 1077 1078Checks whether touch guide mode is enabled. 1079 1080**Atomic service API**: This API can be used in atomic services since API version 11. 1081 1082**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 1083 1084**Return value** 1085 1086| Type | Description | 1087| ------- | ------------------------------------- | 1088| boolean | Returns **true** if accessibility is enabled; returns **false** otherwise.| 1089 1090**Example** 1091 1092```ts 1093import { accessibility } from '@kit.AccessibilityKit'; 1094 1095let status: boolean = accessibility.isOpenTouchGuideSync(); 1096``` 1097 1098## accessibility.isScreenReaderOpenSync<sup>18+</sup> 1099 1100isScreenReaderOpenSync(): boolean 1101 1102Checks whether the screen reader mode is enabled. 1103 1104**Atomic service API**: This API can be used in atomic services since API version 18. 1105 1106**System capability**: SystemCapability.BarrierFree.Accessibility.Vision 1107 1108**Return value** 1109 1110| Type | Description | 1111| ------- | ------------------------------------- | 1112| boolean | Returns **true** if screen reader is enabled; returns **false** otherwise.| 1113 1114**Example** 1115 1116```ts 1117import { accessibility } from '@kit.AccessibilityKit'; 1118 1119let status: boolean = accessibility.isScreenReaderOpenSync(); 1120``` 1121 1122## accessibility.sendEvent<sup>(deprecated)</sup> 1123 1124sendEvent(event: EventInfo): Promise<void> 1125 1126Sends an accessibility event. This API uses a promise to return the result. 1127 1128> **NOTE** 1129> 1130> This API is supported since API version 7 and deprecated since API version 9. 1131> You are advised to use [accessibility.sendAccessibilityEvent()](#accessibilitysendaccessibilityevent9) instead. 1132 1133**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1134 1135**Parameters** 1136 1137| Name | Type | Mandatory | Description | 1138| ----- | ----------------------- | ---- | -------- | 1139| event | [EventInfo](#eventinfo) | Yes | Accessibility event.| 1140 1141**Return value** 1142 1143| Type | Description | 1144| ------------------- | ---------------- | 1145| Promise<void> | Promise that returns no value.| 1146 1147**Example** 1148 1149```ts 1150import { accessibility } from '@kit.AccessibilityKit'; 1151import { BusinessError } from '@kit.BasicServicesKit'; 1152 1153let eventInfo: accessibility.EventInfo = ({ 1154 type: 'click', 1155 bundleName: 'com.example.MyApplication', 1156 triggerAction: 'click', 1157}); 1158 1159accessibility.sendEvent(eventInfo).then(() => { 1160 console.info(`Succeeded in send event,eventInfo is ${eventInfo}`); 1161}).catch((err: BusinessError) => { 1162 console.error(`failed to sendEvent, Code is ${err.code}, message is ${err.message}`); 1163}); 1164``` 1165 1166## accessibility.sendEvent<sup>(deprecated)</sup> 1167 1168sendEvent(event: EventInfo, callback: AsyncCallback<void>): void 1169 1170Sends an accessibility event. This API uses an asynchronous callback to return the result. 1171 1172> **NOTE** 1173> 1174> This API is supported since API version 7 and deprecated since API version 9. 1175> You are advised to use [accessibility.sendAccessibilityEvent()](#accessibilitysendaccessibilityevent9-1) instead. 1176 1177**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1178 1179**Parameters** 1180 1181| Name | Type | Mandatory | Description | 1182| -------- | ------------------------- | ---- | ---------------------------------------- | 1183| event | [EventInfo](#eventinfo) | Yes | Accessibility event. | 1184| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, **err** that contains data is returned.| 1185 1186**Example** 1187 1188```ts 1189import { accessibility } from '@kit.AccessibilityKit'; 1190import { BusinessError } from '@kit.BasicServicesKit'; 1191 1192let eventInfo: accessibility.EventInfo = ({ 1193 type: 'click', 1194 bundleName: 'com.example.MyApplication', 1195 triggerAction: 'click', 1196}); 1197 1198accessibility.sendEvent(eventInfo, (err: BusinessError) => { 1199 if (err) { 1200 console.error(`failed to sendEvent, Code is ${err.code}, message is ${err.message}`); 1201 return; 1202 } 1203 console.info(`Succeeded in sendEvent, eventInfo is ${eventInfo}`); 1204}); 1205``` 1206 1207## accessibility.sendAccessibilityEvent<sup>9+</sup> 1208 1209sendAccessibilityEvent(event: EventInfo): Promise<void> 1210 1211Sends an accessibility event. This API uses a promise to return the result. 1212 1213**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1214 1215**Parameters** 1216 1217| Name | Type | Mandatory | Description | 1218| ----- | ----------------------- | ---- | -------- | 1219| event | [EventInfo](#eventinfo) | Yes | Accessibility event.| 1220 1221**Return value** 1222 1223| Type | Description | 1224| ------------------- | ---------------- | 1225| Promise<void> | Promise that returns no value.| 1226 1227**Error codes** 1228 1229For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 1230 1231| ID| Error Message| 1232| ------- | -------------------------------- | 1233| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1234 1235**Example** 1236 1237```ts 1238import { accessibility } from '@kit.AccessibilityKit'; 1239import { BusinessError } from '@kit.BasicServicesKit'; 1240 1241let eventInfo: accessibility.EventInfo = ({ 1242 type: 'click', 1243 bundleName: 'com.example.MyApplication', 1244 triggerAction: 'click', 1245}); 1246 1247accessibility.sendAccessibilityEvent(eventInfo).then(() => { 1248 console.info(`Succeeded in send event,eventInfo is ${eventInfo}`); 1249}).catch((err: BusinessError) => { 1250 console.error(`failed to send event , Code is ${err.code}, message is ${err.message}`); 1251}); 1252``` 1253 1254## accessibility.sendAccessibilityEvent<sup>9+</sup> 1255 1256sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback<void>): void 1257 1258Sends an accessibility event. This API uses an asynchronous callback to return the result. 1259 1260**System capability**: SystemCapability.BarrierFree.Accessibility.Core 1261 1262**Parameters** 1263 1264| Name | Type | Mandatory | Description | 1265| -------- | ------------------------- | ---- | ---------------------------------------- | 1266| event | [EventInfo](#eventinfo) | Yes | Accessibility event. | 1267| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation fails, **err** that contains data is returned.| 1268 1269**Error codes** 1270 1271For details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 1272 1273| ID| Error Message| 1274| ------- | -------------------------------- | 1275| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1276 1277**Example** 1278 1279```ts 1280import { accessibility } from '@kit.AccessibilityKit'; 1281import { BusinessError } from '@kit.BasicServicesKit'; 1282 1283let eventInfo: accessibility.EventInfo = ({ 1284 type: 'click', 1285 bundleName: 'com.example.MyApplication', 1286 triggerAction: 'click', 1287}); 1288 1289accessibility.sendAccessibilityEvent(eventInfo, (err: BusinessError) => { 1290 if (err) { 1291 console.error(`failed to send event, Code is ${err.code}, message is ${err.message}`); 1292 return; 1293 } 1294 console.info(`Succeeded in send event, eventInfo is ${eventInfo}`); 1295}); 1296``` 1297 1298**Example of auto-focusing:** 1299 1300```ts 1301@Entry 1302@Component 1303struct Index { 1304 1305 build() { 1306 Column() { 1307 // Add the ID attribute to the component to be focused. The uniqueness of the ID is ensured by the user. 1308 Button ('Component to be focused').id ('click') 1309 } 1310 } 1311} 1312``` 1313```ts 1314import { accessibility } from '@kit.AccessibilityKit'; 1315import { BusinessError } from '@kit.BasicServicesKit'; 1316 1317let eventInfo: accessibility.EventInfo = ({ 1318 type: 'requestFocusForAccessibility', 1319 bundleName: 'com.example.MyApplication', 1320 triggerAction: 'common', 1321 customId: 'click' // ID of the component to be focused. 1322}); 1323 1324accessibility.sendAccessibilityEvent(eventInfo, (err: BusinessError) => { 1325 if (err) { 1326 console.error(`failed to send event, Code is ${err.code}, message is ${err.message}`); 1327 return; 1328 } 1329 console.info(`Succeeded in send event, eventInfo is ${eventInfo}`); 1330}); 1331``` 1332 1333**Example of resource-supported auto-broadcasting<sup>18+</sup>:** 1334 1335```ts 1336import { accessibility } from '@kit.AccessibilityKit'; 1337import { BusinessError } from '@kit.BasicServicesKit'; 1338 1339let eventInfo: accessibility.EventInfo = ({ 1340 type: 'announceForAccessibility', 1341 bundleName: 'com.example.MyApplication', 1342 triggerAction: 'common', 1343 textResourceAnnouncedForAccessibility: $r('app.string.ResourceName'), 1344}); 1345 1346accessibility.sendAccessibilityEvent(eventInfo, (err: BusinessError) => { 1347 if (err) { 1348 console.error(`failed to send event, Code is ${err.code}, message is ${err.message}`); 1349 return; 1350 } 1351 console.info(`Succeeded in send event, eventInfo is ${eventInfo}`); 1352}); 1353``` 1354