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