• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# AccessibilityExtensionContext (辅助功能扩展上下文)
2
3AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境,继承自ExtensionContext。
4
5辅助功能扩展上下文模块提供辅助功能扩展的上下文环境的能力,包括允许配置辅助应用关注信息类型、查询节点信息、手势注入等。
6
7> **说明:**
8>
9> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10>
11
12## 使用说明
13
14在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例。
15
16```ts
17import AccessibilityExtensionAbility, {
18  AccessibilityExtensionContext,
19} from '@ohos.application.AccessibilityExtensionAbility';
20
21let axContext: AccessibilityExtensionContext;
22
23class EntryAbility extends AccessibilityExtensionAbility {
24  axContext = this.context;
25}
26```
27
28## FocusDirection
29
30表示查询下一焦点元素的方向。
31
32**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
33
34| 名称       | 说明      |
35| -------- | ------- |
36| up       | 表示向上查询。 |
37| down     | 表示向下查询。 |
38| left     | 表示向左查询。 |
39| right    | 表示向右查询。 |
40| forward  | 表示向前查询。 |
41| backward | 表示向后查询。 |
42
43## FocusType
44
45表示查询焦点元素的类型。
46
47**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
48
49| 名称            | 说明          |
50| ------------- | ----------- |
51| accessibility | 表示无障碍的焦点类型。 |
52| normal        | 表示普通的焦点类型。  |
53
54## Rect
55
56表示矩形区域。
57
58**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
59
60| 名称     | 类型     | 可读   | 可写   | 说明        |
61| ------ | ------ | ---- | ---- | --------- |
62| left   | number | 是    | 否    | 矩形区域的左边界。 |
63| top    | number | 是    | 否    | 矩形区域的上边界。 |
64| width  | number | 是    | 否    | 矩形区域的宽度。  |
65| height | number | 是    | 否    | 矩形区域的高度。  |
66
67## WindowType
68
69表示窗口的类型。
70
71**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core
72
73| 名称          | 说明        |
74| ----------- | --------- |
75| application | 表示应用窗口类型。 |
76| system      | 表示系统窗口类型。 |
77
78## AccessibilityExtensionContext.setTargetBundleName
79
80setTargetBundleName(targetNames: Array\<string>): Promise\<void>;
81
82设置关注的目标包名,使用Promise异步回调。
83
84**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
85
86**参数:**
87
88| 参数名         | 类型                  | 必填   | 说明       |
89| ----------- | ------------------- | ---- | -------- |
90| targetNames | Array&lt;string&gt; | 是    | 关注的目标包名。 |
91
92**返回值:**
93
94| 类型                  | 说明               |
95| ------------------- | ---------------- |
96| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
97
98**示例:**
99
100```ts
101let targetNames = ['com.ohos.xyz'];
102
103try {
104  axContext.setTargetBundleName(targetNames).then(() => {
105    console.info('set target bundle names success');
106  }).catch((err: object) => {
107    console.error(`failed to set target bundle names, because ${JSON.stringify(err)}`);
108  });
109} catch (exception) {
110  console.error(`failed to set target bundle names, because ${JSON.stringify(exception)}`);
111}
112```
113
114## AccessibilityExtensionContext.setTargetBundleName
115
116setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>): void;
117
118设置关注的目标包名,使用callback异步回调。
119
120**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
121
122**参数:**
123
124| 参数名         | 类型                        | 必填   | 说明                                       |
125| ----------- | ------------------------- | ---- | ---------------------------------------- |
126| targetNames | Array&lt;string&gt;       | 是    | 关注的目标包名。                                 |
127| callback    | AsyncCallback&lt;void&gt; | 是    | 回调函数,如果设置关注的目标包名失败,则AsyncCallback中err有数据返回。 |
128
129**示例:**
130
131```ts
132import { BusinessError } from '@ohos.base';
133
134let targetNames = ['com.ohos.xyz'];
135try {
136  axContext.setTargetBundleName(targetNames, (err: BusinessError<void>) => {
137    if (err) {
138      console.error(`failed to set target bundle names, because ${JSON.stringify(err)}`);
139      return;
140    }
141    console.info('set target bundle names success');
142  });
143} catch (exception) {
144  console.error(`failed to set target bundle names, because ${JSON.stringify(exception)}`);
145}
146```
147
148## AccessibilityExtensionContext.getFocusElement
149
150getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>;
151
152获取焦点元素, 使用Promise异步回调。
153
154**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
155
156**参数:**
157
158| 参数名                  | 类型      | 必填   | 说明                  |
159| -------------------- | ------- | ---- | ------------------- |
160| isAccessibilityFocus | boolean | 否    | 获取的是否是无障碍焦点元素,默认为否。 |
161
162**返回值:**
163
164| 类型                                  | 说明                     |
165| ----------------------------------- | ---------------------- |
166| Promise&lt;AccessibilityElement&gt; | Promise对象,返回当前对应的焦点元素。 |
167
168**错误码:**
169
170以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
171
172| 错误码ID   | 错误信息                                     |
173| ------- | ---------------------------------------- |
174| 9300003 | Do not have accessibility right for this operation. |
175
176**示例:**
177
178```ts
179import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
180
181let focusElement: AccessibilityElement;
182try {
183  axContext.getFocusElement().then((data: AccessibilityElement) => {
184    focusElement = data;
185    console.log('get focus element success');
186  }).catch((err: object) => {
187    console.error(`failed to get focus element, because ${JSON.stringify(err)}`);
188  });
189} catch (exception) {
190  console.error(`failed to get focus element, because ${JSON.stringify(exception)}`);
191}
192```
193
194## AccessibilityExtensionContext.getFocusElement
195
196getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;
197
198获取焦点元素, 使用callback异步回调。
199
200**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
201
202**参数:**
203
204| 参数名      | 类型                                       | 必填   | 说明                |
205| -------- | ---------------------------------------- | ---- | ----------------- |
206| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回当前对应的焦点元素。 |
207
208**错误码:**
209
210以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
211
212| 错误码ID   | 错误信息                                     |
213| ------- | ---------------------------------------- |
214| 9300003 | Do not have accessibility right for this operation. |
215
216**示例:**
217
218```ts
219import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
220import { BusinessError } from '@ohos.base';
221
222let focusElement: AccessibilityElement;
223try {
224  axContext.getFocusElement((err: BusinessError<void>, data: AccessibilityElement) => {
225    if (err) {
226      console.error(`failed to get focus element, because ${JSON.stringify(err)}`);
227      return;
228    }
229    focusElement = data;
230    console.info('get focus element success');
231  });
232} catch (exception) {
233  console.error(`failed to get focus element, because ${JSON.stringify(exception)}`);
234}
235```
236
237## AccessibilityExtensionContext.getFocusElement
238
239getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<AccessibilityElement>): void;
240
241获取焦点元素, 使用callback异步回调。
242
243**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
244
245**参数:**
246
247| 参数名                  | 类型                                       | 必填   | 说明                |
248| -------------------- | ---------------------------------------- | ---- | ----------------- |
249| isAccessibilityFocus | boolean                                  | 是    | 获取的是否是无障碍焦点元素。    |
250| callback             | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回当前对应的焦点元素。 |
251
252**错误码:**
253
254以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
255
256| 错误码ID   | 错误信息                                     |
257| ------- | ---------------------------------------- |
258| 9300003 | Do not have accessibility right for this operation. |
259
260**示例:**
261
262```ts
263import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
264import { BusinessError } from '@ohos.base';
265
266let focusElement: AccessibilityElement;
267let isAccessibilityFocus = true;
268
269try {
270  axContext.getFocusElement(isAccessibilityFocus, (err: BusinessError<void>, data: AccessibilityElement) => {
271    if (err) {
272      console.error(`failed to get focus element, because ${JSON.stringify(err)}`);
273      return;
274    }
275    focusElement = data;
276    console.info('get focus element success');
277  });
278} catch (exception) {
279  console.error(`failed to get focus element, because ${JSON.stringify(exception)}`);
280}
281```
282## AccessibilityExtensionContext.getWindowRootElement
283
284getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>;
285
286获取指定窗口的根节点元素, 使用Promise异步回调。
287
288**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
289
290**参数:**
291
292| 参数名      | 类型     | 必填   | 说明                     |
293| -------- | ------ | ---- | ---------------------- |
294| windowId | number | 否    | 指定窗口的编号,未指定则从当前活跃窗口获取。 |
295
296**返回值:**
297
298| 类型                                  | 说明                     |
299| ----------------------------------- | ---------------------- |
300| Promise&lt;AccessibilityElement&gt; | Promise对象,返回指定窗口的根节点元素。 |
301
302**错误码:**
303
304以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
305
306| 错误码ID   | 错误信息                                     |
307| ------- | ---------------------------------------- |
308| 9300003 | Do not have accessibility right for this operation. |
309
310**示例:**
311
312```ts
313import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
314
315let rootElement: AccessibilityElement;
316try {
317  axContext.getWindowRootElement().then((data: AccessibilityElement) => {
318    rootElement = data;
319    console.log('get root element of the window success');
320  }).catch((err: object) => {
321    console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`);
322  });
323} catch (exception) {
324  console.error(`failed to get root element of the window, ${JSON.stringify(exception)}`);
325}
326```
327
328## AccessibilityExtensionContext.getWindowRootElement
329
330getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;
331
332获取指定窗口的根节点元素, 使用callback异步回调。
333
334**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
335
336**参数:**
337
338| 参数名      | 类型                                       | 必填   | 说明                 |
339| -------- | ---------------------------------------- | ---- | ------------------ |
340| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回指定窗口的根节点元素。 |
341
342**错误码:**
343
344以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
345
346| 错误码ID   | 错误信息                                     |
347| ------- | ---------------------------------------- |
348| 9300003 | Do not have accessibility right for this operation. |
349
350**示例:**
351
352```ts
353import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
354import { BusinessError } from '@ohos.base';
355
356let rootElement: AccessibilityElement;
357try {
358  axContext.getWindowRootElement((err: BusinessError<void>
359                                  , data: AccessibilityElement) => {
360    if (err) {
361      console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`);
362      return;
363    }
364    rootElement = data;
365    console.info('get root element of the window success');
366  });
367} catch (exception) {
368  console.error(`failed to get root element of the window, because ${JSON.stringify(exception)}`);
369}
370```
371
372## AccessibilityExtensionContext.getWindowRootElement
373
374getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityElement>): void;
375
376获取指定窗口的根节点元素, 使用callback异步回调。
377
378**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
379
380**参数:**
381
382| 参数名      | 类型                                       | 必填   | 说明                     |
383| -------- | ---------------------------------------- | ---- | ---------------------- |
384| windowId | number                                   | 是    | 指定窗口的编号,未指定则从当前活跃窗口获取。 |
385| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回指定窗口的根节点元素。     |
386
387**错误码:**
388
389以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
390
391| 错误码ID   | 错误信息                                     |
392| ------- | ---------------------------------------- |
393| 9300003 | Do not have accessibility right for this operation. |
394
395**示例:**
396
397```ts
398import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
399import { BusinessError } from '@ohos.base';
400
401let rootElement: AccessibilityElement;
402let windowId = 10;
403
404try {
405  axContext.getWindowRootElement(windowId, (err: BusinessError<void>, data: AccessibilityElement) => {
406    if (err) {
407      console.error(`failed to get root element of the window, because ${JSON.stringify(err)}`);
408      return;
409    }
410    rootElement = data;
411    console.info('get root element of the window success');
412  });
413} catch (exception) {
414  console.error(`failed to get root element of the window, because ${JSON.stringify(exception)}`);
415}
416```
417
418## AccessibilityExtensionContext.getWindows
419
420getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;
421
422获取指定屏幕中的所有窗口, 使用Promise异步回调。
423
424**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
425
426**参数:**
427
428| 参数名       | 类型     | 必填   | 说明                    |
429| --------- | ------ | ---- | --------------------- |
430| displayId | number | 否    | 指定的屏幕编号,未指定则从默认主屏幕获取。 |
431
432**返回值:**
433
434| 类型                                       | 说明                     |
435| ---------------------------------------- | ---------------------- |
436| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise对象,返回指定屏幕的所有窗口。 |
437
438**错误码:**
439
440以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
441
442| 错误码ID   | 错误信息                                     |
443| ------- | ---------------------------------------- |
444| 9300003 | Do not have accessibility right for this operation. |
445
446**示例:**
447
448```ts
449import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
450
451let windows: AccessibilityElement[];
452try {
453  axContext.getWindows().then((data: AccessibilityElement[]) => {
454    windows = data;
455    console.log('get windows success');
456  }).catch((err: object) => {
457    console.error(`failed to get windows, because ${JSON.stringify(err)}`);
458  });
459} catch (exception) {
460  console.error(`failed to get windows, because ${JSON.stringify(exception)}`);
461}
462```
463
464## AccessibilityExtensionContext.getWindows
465
466getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
467
468获取指定屏幕中的所有窗口, 使用callback异步回调。
469
470**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
471
472**参数:**
473
474| 参数名      | 类型                                       | 必填   | 说明                |
475| -------- | ---------------------------------------- | ---- | ----------------- |
476| callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是    | 回调函数,返回指定屏幕的所有窗口。 |
477
478**错误码:**
479
480以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
481
482| 错误码ID   | 错误信息                                     |
483| ------- | ---------------------------------------- |
484| 9300003 | Do not have accessibility right for this operation. |
485
486**示例:**
487
488```ts
489import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
490import { BusinessError } from '@ohos.base';
491
492let windows: AccessibilityElement[];
493try {
494  axContext.getWindows((err: BusinessError<void>, data: AccessibilityElement[]) => {
495    if (err) {
496      console.error(`failed to get windows, because ${JSON.stringify(err)}`);
497      return;
498    }
499    windows = data;
500    console.info('get windows success');
501  });
502} catch (exception) {
503  console.error(`failed to get windows, because ${JSON.stringify(exception)}`);
504}
505```
506
507## AccessibilityExtensionContext.getWindows
508
509getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
510
511获取指定屏幕中的所有窗口, 使用callback异步回调。
512
513**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
514
515**参数:**
516
517| 参数名       | 类型                                       | 必填   | 说明                    |
518| --------- | ---------------------------------------- | ---- | --------------------- |
519| displayId | number                                   | 是    | 指定的屏幕编号,未指定则从默认主屏幕获取。 |
520| callback  | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是    | 回调函数,返回指定屏幕的所有窗口。     |
521
522**错误码:**
523
524以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
525
526| 错误码ID   | 错误信息                                     |
527| ------- | ---------------------------------------- |
528| 9300003 | Do not have accessibility right for this operation. |
529
530**示例:**
531
532```ts
533import { AccessibilityElement } from '@ohos.application.AccessibilityExtensionAbility';
534import { BusinessError } from '@ohos.base';
535
536let windows: AccessibilityElement[];
537let displayId = 10;
538try {
539  axContext.getWindows(displayId, (err: BusinessError<void>, data: AccessibilityElement[]) => {
540    if (err) {
541      console.error(`failed to get windows, because ${JSON.stringify(err)}`);
542      return;
543    }
544    windows = data;
545    console.info('get windows success');
546  });
547} catch (exception) {
548  console.error(`failed to get windows, because ${JSON.stringify(exception)}`);
549}
550```
551
552## AccessibilityExtensionContext.injectGesture<sup>(deprecated)</sup>
553
554injectGesture(gesturePath: GesturePath): Promise\<void>;
555
556注入手势,使用Promise异步回调。
557
558**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
559
560**参数:**
561
562| 参数名         | 类型                                       | 必填   | 说明         |
563| ----------- | ---------------------------------------- | ---- | ---------- |
564| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是    | 表示手势的路径信息。 |
565
566**返回值:**
567
568| 类型                  | 说明               |
569| ------------------- | ---------------- |
570| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
571
572**错误码:**
573
574以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
575
576| 错误码ID   | 错误信息                                     |
577| ------- | ---------------------------------------- |
578| 9300003 | Do not have accessibility right for this operation. |
579
580**示例:**
581
582```ts
583import GesturePath from '@ohos.accessibility.GesturePath';
584import GesturePoint from '@ohos.accessibility.GesturePoint';
585
586let gesturePath: GesturePath.GesturePath = new GesturePath.GesturePath(100);
587try {
588  for (let i = 0; i < 10; i++) {
589    let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
590    gesturePath.points.push(gesturePoint);
591  }
592  axContext.injectGesture(gesturePath).then(() => {
593    console.info('inject gesture success');
594  }).catch((err: object) => {
595    console.error(`failed to inject gesture, because ${JSON.stringify(err)}`);
596  });
597} catch (exception) {
598  console.error(`failed to inject gesture, because ${JSON.stringify(exception)}`);
599}
600```
601## AccessibilityExtensionContext.injectGesture<sup>(deprecated)</sup>
602
603injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
604
605注入手势,使用callback异步回调。
606
607**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
608
609**参数:**
610
611| 参数名         | 类型                                       | 必填   | 说明                  |
612| ----------- | ---------------------------------------- | ---- | ------------------- |
613| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是    | 表示手势的路径信息。          |
614| callback    | AsyncCallback&lt;void&gt;                | 是    | 回调函数,表示注入手势执行结果的回调。 |
615
616**错误码:**
617
618以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
619
620| 错误码ID   | 错误信息                                     |
621| ------- | ---------------------------------------- |
622| 9300003 | Do not have accessibility right for this operation. |
623
624**示例:**
625
626```ts
627import GesturePath from '@ohos.accessibility.GesturePath';
628import GesturePoint from '@ohos.accessibility.GesturePoint';
629
630let gesturePath: GesturePath.GesturePath = new GesturePath.GesturePath(100);
631try {
632  for (let i = 0; i < 10; i++) {
633    let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
634    gesturePath.points.push(gesturePoint);
635  }
636  axContext.injectGesture(gesturePath, (err) => {
637    if (err) {
638      console.error(`failed to inject gesture, because ${JSON.stringify(err)}`);
639      return;
640    }
641    console.info('inject gesture success');
642  });
643} catch (exception) {
644  console.error(`failed to inject gesture, because ${JSON.stringify(exception)}`);
645}
646```
647## AccessibilityExtensionContext.injectGestureSync<sup>10+</sup>
648
649injectGestureSync(gesturePath: GesturePath): void
650
651注入手势。
652
653**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
654
655**参数:**
656
657| 参数名      | 类型                                                         | 必填 | 说明                 |
658| ----------- | ------------------------------------------------------------ | ---- | -------------------- |
659| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是   | 表示手势的路径信息。 |
660
661**错误码:**
662
663以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
664
665| 错误码ID | 错误信息                                            |
666| -------- | --------------------------------------------------- |
667| 9300003  | Do not have accessibility right for this operation. |
668
669**示例:**
670
671```ts
672import GesturePath from '@ohos.accessibility.GesturePath';
673import GesturePoint from '@ohos.accessibility.GesturePoint';
674
675let gesturePath: GesturePath.GesturePath = new GesturePath.GesturePath(100);
676try {
677  for (let i = 0; i < 10; i++) {
678    let gesturePoint = new GesturePoint.GesturePoint(100, i * 200);
679    gesturePath.points.push(gesturePoint);
680  }
681  axContext.injectGestureSync(gesturePath);
682} catch (exception) {
683  console.error(`failed to inject gesture, because ${JSON.stringify(exception)}`);
684}
685```
686
687## AccessibilityElement<sup>9+</sup>
688
689无障碍节点元素, 在调用AccessibilityElement的方法前,需要先通过[AccessibilityExtensionContext.getFocusElement()](#accessibilityextensioncontextgetfocuselement)或者[AccessibilityExtensionContext.getWindowRootElement()](#accessibilityextensioncontextgetwindowrootelement)获取AccessibilityElement实例。
690
691**系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Core
692
693### attributeNames
694
695attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;
696
697获取节点元素的所有属性名称,使用Promise异步回调。
698
699**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
700
701**返回值:**
702
703| 类型                            | 说明                       |
704| ----------------------------- | ------------------------ |
705| Promise&lt;Array&lt;T&gt;&gt; | Promise对象,返回节点元素的所有属性名称。 |
706
707**示例:**
708
709```ts
710import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
711
712let attributeNames: ElementAttributeKeys;
713rootElement.attributeNames().then((data: ElementAttributeKeys) => {
714  console.log('get attribute names success');
715  attributeNames = data;
716}).catch((err: object) => {
717  console.log(`failed to get attribute names, because ${JSON.stringify(err)}`);
718});
719```
720### attributeNames
721
722attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\<Array\<T>>): void;
723
724获取节点元素的所有属性名称,使用callback异步回调。
725
726**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
727
728**参数:**
729
730| 参数名      | 类型                                  | 必填   | 说明                  |
731| -------- | ----------------------------------- | ---- | ------------------- |
732| callback | AsyncCallback&lt;Array&lt;T&gt;&gt; | 是    | 回调函数,返回节点元素的所有属性名称。 |
733
734**示例:**
735
736```ts
737import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
738import { BusinessError } from '@ohos.base';
739
740let attributeNames: ElementAttributeKeys[];
741rootElement.attributeNames((err: BusinessError<void>, data: ElementAttributeKeys[]) => {
742  if (err) {
743    console.error(`failed to get attribute names, because ${JSON.stringify(err)}`);
744    return;
745  }
746  attributeNames = data;
747  console.info('get attribute names success');
748});
749```
750### attributeValue
751
752attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promise\<ElementAttributeValues[T]>;
753
754根据属性名称获取属性值,使用Promise异步回调。
755
756**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
757
758**参数:**
759
760| 参数名           | 类型   | 必填   | 说明       |
761| ------------- | ---- | ---- | -------- |
762| attributeName | ElementAttributeKeys  | 是    | 表示属性的名称。 |
763
764**返回值:**
765
766| 类型                                       | 说明                          |
767| ---------------------------------------- | --------------------------- |
768| Promise&lt;ElementAttributeValues[T]&gt; | Promise对象,返回根据节点属性名称获取的属性值。 |
769
770**错误码:**
771
772以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
773
774| 错误码ID   | 错误信息                          |
775| ------- | ----------------------------- |
776| 9300004 | This property does not exist. |
777
778**示例:**
779
780```ts
781import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
782
783let attributeName: ElementAttributeKeys = 'bundleName';
784let attributeValue: string;
785try {
786  rootElement.attributeValue(attributeName).then((data: string) => {
787    console.log('get attribute value by name success');
788    attributeValue = data;
789  }).catch((err: object) => {
790    console.error(`failed to get attribute value, because ${JSON.stringify(err)}`);
791  });
792} catch (exception) {
793  console.error(`failed to get attribute value, because ${JSON.stringify(exception)}`);
794}
795```
796### attributeValue
797
798attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
799    callback: AsyncCallback\<ElementAttributeValues[T]>): void;
800
801根据属性名称获取属性值,使用callback异步回调。
802
803**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
804
805**参数:**
806
807| 参数名           | 类型                                       | 必填   | 说明                     |
808| ------------- | ---------------------------------------- | ---- | ---------------------- |
809| attributeName | ElementAttributeKeys                         | 是    | 表示属性的名称。               |
810| callback      | AsyncCallback&lt;ElementAttributeValues[T]&gt; | 是    | 回调函数,返回根据节点属性名称获取的属性值。 |
811
812**错误码:**
813
814以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
815
816| 错误码ID   | 错误信息                          |
817| ------- | ----------------------------- |
818| 9300004 | This property does not exist. |
819
820**示例:**
821
822```ts
823import { ElementAttributeKeys } from '@ohos.application.AccessibilityExtensionAbility';
824import { BusinessError } from '@ohos.base';
825
826let attributeName: ElementAttributeKeys = 'bundleName';
827let attributeValue: string;
828try {
829  rootElement.attributeValue(attributeName, (err: BusinessError<void>, data: string) => {
830    if (err) {
831      console.error(`failed to get attribute value, because ${JSON.stringify(err)}`);
832      return;
833    }
834    attributeValue = data;
835    console.info('get attribute value success');
836  });
837} catch (exception) {
838  console.error(`failed to get attribute value, because ${JSON.stringify(exception)}`);
839}
840```
841### actionNames
842
843actionNames(): Promise\<Array\<string>>;
844
845获取节点元素支持的所有操作名称,使用Promise异步回调。
846
847**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
848
849**返回值:**
850
851| 类型                                 | 说明                         |
852| ---------------------------------- | -------------------------- |
853| Promise&lt;Array&lt;string&gt;&gt; | Promise对象,返回节点元素支持的所有操作名称。 |
854
855**示例:**
856
857```ts
858let actionNames: string[];
859rootElement.actionNames().then((data: string[]) => {
860  console.log('get action names success');
861  actionNames = data;
862}).catch((err: object) => {
863  console.error(`failed to get action names because ${JSON.stringify(err)}`);
864})
865```
866### actionNames
867
868actionNames(callback: AsyncCallback\<Array\<string>>): void;
869
870获取节点元素支持的所有操作名称,使用callback异步回调。
871
872**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
873
874**参数:**
875
876| 参数名      | 类型                                       | 必填   | 说明                    |
877| -------- | ---------------------------------------- | ---- | --------------------- |
878| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | 是    | 回调函数,返回节点元素支持的所有操作名称。 |
879
880**示例:**
881
882```ts
883let actionNames: string[];
884rootElement.actionNames((err: BusinessError<void>, data: string[]) => {
885  if (err) {
886    console.error(`failed to get action names, because ${JSON.stringify(err)}`);
887    return;
888  }
889  actionNames = data;
890  console.info('get action names success');
891})
892```
893### performAction
894
895performAction(actionName: string, parameters?: object): Promise\<void>;
896
897根据操作名称执行某个操作,使用Promise异步回调。
898
899**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
900
901**参数:**
902
903| 参数名         | 类型                                     | 必填   | 说明             |
904| ----------- | ---------------------------------------- | ---- | -------------- |
905| actionName | string | 是    | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。
906| parameters | object | 否    | 表示执行操作时所需要的参数;默认为空;当前版本暂不支持。     |
907
908**返回值:**
909
910| 类型                  | 说明               |
911| ------------------- | ---------------- |
912| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
913
914**错误码:**
915
916以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
917
918| 错误码ID   | 错误信息                          |
919| ------- | ----------------------------- |
920| 9300005 | This action is not supported. |
921
922**示例:**
923
924```ts
925let actionName = 'action';
926try {
927  rootElement.performAction(actionName).then(() => {
928    console.info('perform action success');
929  }).catch((err: object) => {
930    console.error(`failed to perform action, because ${JSON.stringify(err)}`);
931  });
932} catch (exception) {
933  console.error(`failed to perform action, because ${JSON.stringify(exception)}`);
934}
935```
936### performAction
937
938performAction(actionName: string, callback: AsyncCallback\<void>): void;
939
940根据操作名称执行某个操作,使用callback异步回调。
941
942**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
943
944**参数:**
945
946| 参数名         | 类型                                     | 必填   | 说明             |
947| ----------- | ---------------------------------------- | ---- | -------------- |
948| actionName | string | 是    | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。
949| callback | AsyncCallback&lt;void&gt; | 是    | 回调函数,表示执行指定操作的回调。|
950
951**错误码:**
952
953以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
954
955| 错误码ID   | 错误信息                          |
956| ------- | ----------------------------- |
957| 9300005 | This action is not supported. |
958
959**示例:**
960
961```ts
962import { BusinessError } from '@ohos.base';
963
964let actionName = 'action';
965try {
966  rootElement.performAction(actionName, (err:BusinessError) => {
967    if (err) {
968      console.error(`failed to perform action, because ${JSON.stringify(err)}`);
969      return;
970    }
971    console.info('perform action success');
972  });
973} catch (exception) {
974  console.error(`failed to perform action, because ${JSON.stringify(exception)}`);
975}
976```
977### performAction
978
979performAction(actionName: string, parameters: object, callback: AsyncCallback\<void>): void;
980
981根据操作名称执行某个操作,使用callback异步回调。
982
983**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
984
985**参数:**
986
987| 参数名        | 类型                        | 必填   | 说明                                       |
988| ---------- | ------------------------- | ---- | ---------------------------------------- |
989| actionName | string                    | 是    | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。 |
990| parameters | object                    | 是    | 表示执行操作时所需要的参数;默认为空;当前版本暂不支持。                  |
991| callback   | AsyncCallback&lt;void&gt; | 是    | 回调函数,表示执行指定操作的回调。                        |
992
993**错误码:**
994
995以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
996
997| 错误码ID   | 错误信息                          |
998| ------- | ----------------------------- |
999| 9300005 | This action is not supported. |
1000
1001**示例:**
1002
1003```ts
1004import { BusinessError } from '@ohos.base';
1005
1006let actionName = 'action';
1007let parameters: object = [];
1008try {
1009  rootElement.performAction(actionName, parameters, (err: BusinessError<void>) => {
1010    if (err) {
1011      console.error(`failed to perform action, because ${JSON.stringify(err)}`);
1012      return;
1013    }
1014    console.info('perform action success');
1015  });
1016} catch (exception) {
1017  console.error(`failed to perform action, because ${JSON.stringify(exception)}`);
1018}
1019```
1020### findElement('content')
1021
1022findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>;
1023
1024根据节点内容查询所有节点元素,使用Promise异步回调。
1025
1026**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
1027
1028**参数:**
1029
1030| 参数名       | 类型     | 必填   | 说明                            |
1031| --------- | ------ | ---- | ----------------------------- |
1032| type      | string | 是    | 固定为'content', 表示查找的类型为节点元素内容。 |
1033| condition | string | 是    | 表示查找的条件。                      |
1034
1035**返回值:**
1036
1037| 类型                                       | 说明                            |
1038| ---------------------------------------- | ----------------------------- |
1039| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise对象,返回满足指定查询关键字的所有节点元素。 |
1040
1041**示例:**
1042
1043```ts
1044let condition = 'keyword';
1045let elements: AccessibilityElement[];
1046try {
1047  rootElement.findElement('content', condition).then((data: AccessibilityElement[]) => {
1048    elements = data;
1049    console.log('find element success');
1050  }).catch((err: object) => {
1051    console.error(`failed to find element, because ${JSON.stringify(err)}`);
1052  });
1053} catch (exception) {
1054  console.error(`failed to find element, because ${JSON.stringify(exception)}`);
1055}
1056```
1057### findElement('content')
1058
1059findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
1060
1061根据节点内容查询所有节点元素。
1062
1063**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
1064
1065**参数:**
1066
1067| 参数名       | 类型                                       | 必填   | 说明                           |
1068| --------- | ---------------------------------------- | ---- | ---------------------------- |
1069| type      | string                                   | 是    | 固定为'content',表示查找的类型为节点元素内容。 |
1070| condition | string                                   | 是    | 表示查找的条件。                     |
1071| callback  | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是    | 回调函数,返回满足指定查询关键字的所有节点元素。     |
1072
1073**示例:**
1074
1075```ts
1076import { BusinessError } from '@ohos.base';
1077
1078let condition = 'keyword';
1079let elements: AccessibilityElement[];
1080try {
1081  rootElement.findElement('content', condition, (err: BusinessError<void>, data: AccessibilityElement[]) => {
1082    if (err) {
1083      console.error(`failed to find element, because ${JSON.stringify(err)}`);
1084      return;
1085    }
1086    elements = data;
1087    console.info('find element success');
1088  });
1089} catch (exception) {
1090  console.error(`failed to find element, because ${JSON.stringify(exception)}`);
1091}
1092```
1093### findElement('focusType')
1094
1095findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>;
1096
1097根据焦点元素类型查询节点元素,使用Promise异步回调。
1098
1099**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
1100
1101**参数:**
1102
1103| 参数名       | 类型                      | 必填   | 说明                                 |
1104| --------- | ----------------------- | ---- | ---------------------------------- |
1105| type      | string                  | 是    | 固定为'focusType', 表示查询的类型为节点的焦点元素类型。 |
1106| condition | [FocusType](#focustype) | 是    | 表示查询焦点元素的类型。                       |
1107
1108**返回值:**
1109
1110| 类型                                  | 说明                             |
1111| ----------------------------------- | ------------------------------ |
1112| Promise&lt;AccessibilityElement&gt; | Promise对象,返回满足指定查询焦点元素类型的节点元素。 |
1113
1114**示例:**
1115
1116```ts
1117import { FocusType } from '@ohos.application.AccessibilityExtensionAbility';
1118
1119let condition: FocusType = 'normal';
1120let element: AccessibilityElement;
1121try {
1122  rootElement.findElement('focusType', condition).then((data: AccessibilityElement) => {
1123    element = data;
1124    console.log('find element success');
1125  }).catch((err: object) => {
1126    console.error(`failed to find element, because ${JSON.stringify(err)}`);
1127  });
1128} catch (exception) {
1129  console.error(`failed to find element, because ${JSON.stringify(exception)}`);
1130}
1131```
1132### findElement('focusType')
1133
1134findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void;
1135
1136根据焦点元素类型查询节点元素,使用callback异步回调。
1137
1138**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
1139
1140**参数:**
1141
1142| 参数名       | 类型                                       | 必填   | 说明                                 |
1143| --------- | ---------------------------------------- | ---- | ---------------------------------- |
1144| type      | string                                   | 是    | 固定为'focusType', 表示查询的类型为节点的焦点元素类型。 |
1145| condition | [FocusType](#focustype)                  | 是    | 表示查询焦点元素的类型。                       |
1146| callback  | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回满足指定查询焦点元素类型的节点元素。          |
1147
1148**示例:**
1149
1150```ts
1151import { FocusType } from '@ohos.application.AccessibilityExtensionAbility';
1152import { BusinessError } from '@ohos.base';
1153
1154let condition: FocusType = 'normal';
1155let element: AccessibilityElement;
1156try {
1157  rootElement.findElement('focusType', condition, (err: BusinessError<void>, data: AccessibilityElement) => {
1158    if (err) {
1159      console.error(`failed to find element, because ${JSON.stringify(err)}`);
1160      return;
1161    }
1162    element = data;
1163    console.info('find element success');
1164  });
1165} catch (exception) {
1166  console.error(`failed to find element, because ${JSON.stringify(exception)}`);
1167}
1168```
1169### findElement('focusDirection')
1170
1171findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>;
1172
1173根据下一焦点元素方向查询节点元素,使用Promise异步回调。
1174
1175**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
1176
1177**参数:**
1178
1179| 参数名       | 类型                                | 必填   | 说明                                       |
1180| --------- | --------------------------------- | ---- | ---------------------------------------- |
1181| type      | string                            | 是    | 固定为'focusDirection', 表示查询的类型为节点的下一焦点元素方向。 |
1182| condition | [FocusDirection](#focusdirection) | 是    | 表示查询下一焦点元素的方向。                           |
1183
1184**返回值:**
1185
1186| 类型                                  | 说明                               |
1187| ----------------------------------- | -------------------------------- |
1188| Promise&lt;AccessibilityElement&gt; | Promise对象,返回满足指定查询下一焦点元素方向的节点元素。 |
1189
1190**示例:**
1191
1192```ts
1193import { FocusDirection } from '@ohos.application.AccessibilityExtensionAbility';
1194
1195let condition: FocusDirection = 'up';
1196let element: AccessibilityElement;
1197try {
1198  rootElement.findElement('focusDirection', condition).then((data: AccessibilityElement) => {
1199    element = data;
1200    console.log('find element success');
1201  }).catch((err: object) => {
1202    console.error(`failed to find element, because ${JSON.stringify(err)}`);
1203  });
1204} catch (exception) {
1205  console.error(`failed to find element, because ${JSON.stringify(exception)}`);
1206}
1207```
1208### findElement('focusDirection')
1209
1210findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void;
1211
1212根据下一焦点元素方向查询所有节点元素,使用callback异步回调。
1213
1214**系统能力:**  SystemCapability.BarrierFree.Accessibility.Core
1215
1216**参数:**
1217
1218| 参数名       | 类型                                       | 必填   | 说明                                       |
1219| --------- | ---------------------------------------- | ---- | ---------------------------------------- |
1220| type      | string                                   | 是    | 固定为'focusDirection', 表示查询的类型为节点的下一焦点元素方向。 |
1221| condition | [FocusDirection](#focusdirection)        | 是    | 表示下一查询焦点元素的方向。                           |
1222| callback  | AsyncCallback&lt;AccessibilityElement&gt; | 是    | 回调函数,返回满足指定查询下一焦点元素方向的节点元素。              |
1223
1224**示例:**
1225
1226```ts
1227import { FocusDirection } from '@ohos.application.AccessibilityExtensionAbility';
1228import { BusinessError } from '@ohos.base';
1229
1230let condition: FocusDirection = 'up';
1231let elements: AccessibilityElement;
1232try {
1233  rootElement.findElement('focusDirection', condition, (err: BusinessError<void>, data: AccessibilityElement) => {
1234    if (err) {
1235      console.error(`failed to find element, because ${JSON.stringify(err)}`);
1236      return;
1237    }
1238    elements = data;
1239    console.info('find element success');
1240  });
1241} catch (exception) {
1242  console.error(`failed to find element, because ${JSON.stringify(exception)}`);
1243}
1244```
1245