1# AccessibilityExtensionContext (辅助功能扩展上下文) 2 3AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境,继承自ExtensionContext。 4 5辅助功能扩展上下文模块提供辅助功能扩展的上下文环境的能力,包括允许配置辅助应用关注信息类型、查询节点信息、手势注入等。 6 7> **说明:** 8> 9> - 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 10 11## 使用说明 12 13在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例。 14 15```ts 16import { AccessibilityExtensionAbility } from '@kit.AccessibilityKit'; 17 18class EntryAbility extends AccessibilityExtensionAbility { 19 onConnect(): void { 20 let axContext = this.context; 21 } 22} 23``` 24 25## ElementAttributeValues 26 27节点元素具备的属性名称及属性值类型信息。 28 29**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core 30 31### 属性 32 33| 名称 | 类型 | 可读 | 可写 | 说明 | 34|----------------------|--------------------------------------------------------------------|-----|-----| ------------------- | 35| accessibilityFocused | boolean | 是 | 否 | accessibility焦点状态。 | 36| accessibilityText<sup>12+</sup> | string | 是 | 否 | 元素的无障碍文本信息。 | 37| bundleName | string | 是 | 否 | 应用包名。 | 38| checkable | boolean | 是 | 否 | 元素是否可查。 | 39| checked | boolean | 是 | 否 | 元素是否被检查。 | 40| children | Array<[AccessibilityElement](#accessibilityelement9)> | 是 | 否 | 所有子元素。 | 41| clickable | boolean | 是 | 否 | 是否可点击。 | 42| componentId | number | 是 | 否 | 元素所属的组件ID。 | 43| componentType | string | 是 | 否 | 元素所属的组件类型。 | 44| contents | Array<string> | 是 | 否 | 内容。 | 45| currentIndex | number | 是 | 否 | 当前项的索引。 | 46| description | string | 是 | 否 | 元素的描述信息。 | 47| editable | boolean | 是 | 否 | 元素是否可编辑。 | 48| endIndex | number | 是 | 否 | 屏幕最后显示项的列表索引。 | 49| error | string | 是 | 否 | 错误状态字符串。 | 50| focusable | boolean | 是 | 否 | 元素是否可聚焦。 | 51| hintText | string | 是 | 否 | 提示文本。 | 52| inputType | number | 是 | 否 | 输入文本的类型。 | 53| inspectorKey | string | 是 | 否 | 检查键。 | 54| isActive | boolean | 是 | 否 | 元素是否处于活动状态。 | 55| isEnable | boolean | 是 | 否 | 元素是否启用。 | 56| isHint | boolean | 是 | 否 | 元素是否为提示状态。 | 57| isFocused | boolean | 是 | 否 | 元素是否聚焦。 | 58| isPassword | boolean | 是 | 否 | 元素是否为密码。 | 59| isVisible | boolean | 是 | 否 | 元素是否可见。 | 60| itemCount | number | 是 | 否 | 项目的总数。 | 61| lastContent | string | 是 | 否 | 最后的内容。 | 62| layer | number | 是 | 否 | 该元素的显示层。 | 63| longClickable | boolean | 是 | 否 | 元素是否可长单击。 | 64| pageId | number | 是 | 否 | 页码id。 | 65| parent | [AccessibilityElement](#accessibilityelement9) | 是 | 否 | 元素的父元素。 | 66| pluralLineSupported | boolean | 是 | 否 | 元素是否支持多行文本。 | 67| rect | [Rect](#rect) | 是 | 否 | 元素的面积。 | 68| resourceName | string | 是 | 否 | 元素的资源名称。 | 69| rootElement | [AccessibilityElement](#accessibilityelement9) | 是 | 否 | 窗口元素的根元素。 | 70| screenRect | [Rect](#rect) | 是 | 否 | 元素的显示区域。 | 71| scrollable | boolean | 是 | 否 | 元素是否可滚动。 | 72| selected | boolean | 是 | 否 | 元素是否被选中。 | 73| startIndex | number | 是 | 否 | 在屏幕上的第一个项目的列表索引。 | 74| text | string | 是 | 否 | 元素的文本。 | 75| textLengthLimit | number | 是 | 否 | 元素文本的最大长度限制。 | 76| textMoveUnit | [accessibility.TextMoveUnit](js-apis-accessibility.md#textmoveunit) | 是 | 否 | 文本被读取时的移动单位。 | 77| triggerAction | [accessibility.Action](js-apis-accessibility.md#action) | 是 | 否 | 触发元素事件的动作。 | 78| type | [WindowType](#windowtype) | 是 | 否 | 元素的窗口类型。 | 79| valueMax | number | 是 | 否 | 最大值。 | 80| valueMin | number | 是 | 否 | 最小值。| 81| valueNow | number | 是 | 否 | 当前值。 | 82| windowId | number | 是 | 否 | 窗口id。 | 83| textType<sup>12+</sup> | string | 是 | 否 | 元素的无障碍文本类型,由组件accessibilityTextHint属性配置。 | 84| offset<sup>12+</sup> | number | 是 | 否 | 对于可滚动类控件,如List、Grid,内容区相对控件的顶部坐标滚动的像素偏移量。 | 85| hotArea<sup>12+</sup> | [Rect](#rect) | 是 | 否 | 元素的可触摸区域。 | 86 87## FocusDirection 88 89type FocusDirection = 'up' | 'down' | 'left' | 'right' | 'forward' | 'backward' 90 91表示查询下一焦点元素的方向。 92 93**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core 94 95| 类型 | 说明 | 96| -------- | ------- | 97| 'up' | 表示向上查询。 | 98| 'down' | 表示向下查询。 | 99| 'left' | 表示向左查询。 | 100| 'right' | 表示向右查询。 | 101| 'forward' | 表示向前查询。 | 102| 'backward' | 表示向后查询。 | 103 104## FocusType 105 106type FocusType = 'accessibility' | 'normal' 107 108表示查询焦点元素的类型。 109 110**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core 111 112| 类型 | 说明 | 113| ------------- | ----------- | 114| 'accessibility' | 表示无障碍的焦点类型。 | 115| 'normal' | 表示普通的焦点类型。 | 116 117## Rect 118 119表示矩形区域。 120 121**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core 122 123| 名称 | 类型 | 可读 | 可写 | 说明 | 124| ------ | ------ | ---- | ---- | --------- | 125| left | number | 是 | 否 | 矩形区域的左边界。 | 126| top | number | 是 | 否 | 矩形区域的上边界。 | 127| width | number | 是 | 否 | 矩形区域的宽度。 | 128| height | number | 是 | 否 | 矩形区域的高度。 | 129 130## WindowType 131 132type WindowType = 'application' | 'system' 133 134表示窗口的类型。 135 136**系统能力**:以下各项对应的系统能力均为 SystemCapability.BarrierFree.Accessibility.Core 137 138| 类型 | 说明 | 139| ----------- | --------- | 140| 'application' | 表示应用窗口类型。 | 141| 'system' | 表示系统窗口类型。 | 142 143## AccessibilityExtensionContext.setTargetBundleName<sup>(deprecated)</sup> 144 145setTargetBundleName(targetNames: Array\<string>): Promise\<void>; 146 147设置关注的目标包名,使用Promise异步回调。 148 149> **说明:** 150> 151> 从API version 12开始废弃。 152 153**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 154 155**参数:** 156 157| 参数名 | 类型 | 必填 | 说明 | 158| ----------- | ------------------- | ---- | -------- | 159| targetNames | Array<string> | 是 | 设置关注应用的包名,服务接收关注应用的无障碍事件,默认接收所有应用的无障碍事件,取消关注应用则传空数组。 | 160 161**返回值:** 162 163| 类型 | 说明 | 164| ------------------- | ---------------- | 165| Promise<void> | 无返回结果的Promise对象。 | 166 167**错误码:** 168 169以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 170 171| 错误码ID | 错误信息 | 172| ------- | -------------------------------- | 173| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 174 175**示例:** 176 177```ts 178import { BusinessError } from '@kit.BasicServicesKit'; 179 180let targetNames = ['com.ohos.xyz']; 181axContext.setTargetBundleName(targetNames).then(() => { 182 console.info(`Succeeded in set target bundle names, targetNames is ${targetNames}`); 183}).catch((err: BusinessError) => { 184 console.error(`failed to set target bundle names, Code is ${err.code}, message is ${err.message}`); 185}) 186``` 187 188## AccessibilityExtensionContext.setTargetBundleName<sup>(deprecated)</sup> 189 190setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>): void; 191 192设置关注的目标包名,使用callback异步回调。 193 194> **说明:** 195> 196> 从API version 12开始废弃。 197 198**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 199 200**参数:** 201 202| 参数名 | 类型 | 必填 | 说明 | 203| ----------- | ------------------------- | ---- | ---------------------------------------- | 204| targetNames | Array<string> | 是 | 设置关注应用的包名,服务接收关注应用的无障碍事件,默认接收所有应用的无障碍事件,取消关注应用则传空数组。 | 205| callback | AsyncCallback<void> | 是 | 回调函数,如果设置关注的目标包名失败,则AsyncCallback中err有数据返回。 | 206 207**错误码:** 208 209以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 210 211| 错误码ID | 错误信息 | 212| ------- | -------------------------------- | 213| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 214 215**示例:** 216 217```ts 218import { BusinessError } from '@kit.BasicServicesKit'; 219 220let targetNames = ['com.ohos.xyz']; 221try { 222 axContext.setTargetBundleName(targetNames, (err: BusinessError) => { 223 if (err && err.code) { 224 console.error(`failed to set target bundle names, Code is ${err.code}, message is ${err.message}`); 225 return; 226 } 227 console.info(`Succeeded in set target bundle names, targetNames is ${targetNames}`); 228 }); 229} catch (error) { 230 console.error(`failed to set target bundle names, Because ${JSON.stringify(error)}`); 231} 232``` 233 234## AccessibilityExtensionContext.getFocusElement<sup>(deprecated)</sup> 235 236getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>; 237 238获取焦点元素, 使用Promise异步回调。 239 240> **说明:** 241> 242> 从API version 12开始废弃。 243 244**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 245 246**参数:** 247 248| 参数名 | 类型 | 必填 | 说明 | 249| -------------------- | ------- | ---- | ------------------- | 250| isAccessibilityFocus | boolean | 否 | 获取的是否是无障碍焦点元素,True表示是,False表示否,默认为否。 | 251 252**返回值:** 253| 类型 | 说明 | 254| ----------------------------------- | ---------------------- | 255| Promise<[AccessibilityElement](#accessibilityelement9)> | Promise对象,返回当前对应的焦点元素。 | 256 257**错误码:** 258 259以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 260 261| 错误码ID | 错误信息 | 262| ------- | ---------------------------------------- | 263| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 264| 9300003 | No accessibility permission to perform the operation. | 265 266**示例:** 267 268```ts 269import { AccessibilityElement } from '@kit.AccessibilityKit'; 270import { BusinessError } from '@kit.BasicServicesKit'; 271 272let rootElement: AccessibilityElement; 273 274axContext.getFocusElement().then((data: AccessibilityElement) => { 275 rootElement = data; 276 console.log(`Succeeded in get focus element,${JSON.stringify(data)}`); 277}).catch((err: BusinessError) => { 278 console.error(`failed to get focus element, Code is ${err.code}, message is ${err.message}`); 279}) 280``` 281 282## AccessibilityExtensionContext.getFocusElement<sup>(deprecated)</sup> 283 284getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void; 285 286获取焦点元素, 使用callback异步回调。 287 288> **说明:** 289> 290> 从API version 12开始废弃。 291 292**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 293 294**参数:** 295 296| 参数名 | 类型 | 必填 | 说明 | 297| -------- | ---------------------------------------- | ---- | ----------------- | 298| callback | AsyncCallback<[AccessibilityElement](#accessibilityelement9)> | 是 | 回调函数,返回当前对应的焦点元素。 | 299 300**错误码:** 301 302以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 303 304| 错误码ID | 错误信息 | 305| ------- | ---------------------------------------- | 306| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 307| 9300003 | No accessibility permission to perform the operation. | 308 309**示例:** 310 311```ts 312import { AccessibilityElement } from '@kit.AccessibilityKit'; 313import { BusinessError } from '@kit.BasicServicesKit'; 314 315let rootElement: AccessibilityElement; 316 317axContext.getFocusElement((err: BusinessError, data: AccessibilityElement) => { 318 if (err && err.code) { 319 console.error(`failed to get focus element, Code is ${err.code}, message is ${err.message}`); 320 return; 321 } 322 rootElement = data; 323 console.info(`Succeeded in get focus element, ${JSON.stringify(data)}`); 324}); 325``` 326 327## AccessibilityExtensionContext.getFocusElement<sup>(deprecated)</sup> 328 329getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<AccessibilityElement>): void; 330 331获取焦点元素, 使用callback异步回调。 332 333> **说明:** 334> 335> 从API version 12开始废弃。 336 337**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 338 339**参数:** 340 341| 参数名 | 类型 | 必填 | 说明 | 342| -------------------- | ---------------------------------------- | ---- | ----------------- | 343| isAccessibilityFocus | boolean | 是 | 获取的是否是无障碍焦点元素,True表示是,False表示否。 | 344| callback | AsyncCallback<[AccessibilityElement](#accessibilityelement9)> | 是 | 回调函数,返回当前对应的焦点元素。 | 345 346**错误码:** 347 348以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 349 350| 错误码ID | 错误信息 | 351| ------- | ---------------------------------------- | 352| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 353| 9300003 | No accessibility permission to perform the operation. | 354 355**示例:** 356 357```ts 358import { AccessibilityElement } from '@kit.AccessibilityKit'; 359import { BusinessError } from '@kit.BasicServicesKit'; 360 361let isAccessibilityFocus = true; 362let rootElement: AccessibilityElement; 363 364axContext.getFocusElement(isAccessibilityFocus, (err: BusinessError, data: AccessibilityElement)=> { 365 if (err && err.code) { 366 console.error(`failed to get focus element, Code is ${err.code}, message is ${err.message}`); 367 return; 368 } 369 rootElement = data; 370 console.info(`Succeeded in get focus element, ${JSON.stringify(data)}`); 371}); 372``` 373 374## AccessibilityExtensionContext.getWindowRootElement<sup>(deprecated)</sup> 375 376getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>; 377 378获取指定窗口的根节点元素, 使用Promise异步回调。 379 380> **说明:** 381> 382> 从API version 12开始废弃。 383 384**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 385 386**参数:** 387 388| 参数名 | 类型 | 必填 | 说明 | 389| -------- | ------ | ---- | ---------------------- | 390| windowId | number | 否 | 指定窗口的编号,未指定则从当前活跃窗口获取。 | 391 392**返回值:** 393 394| 类型 | 说明 | 395| ----------------------------------- | ---------------------- | 396| Promise<[AccessibilityElement](#accessibilityelement9)> | Promise对象,返回指定窗口的根节点元素。 | 397 398**错误码:** 399 400以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 401 402| 错误码ID | 错误信息 | 403| ------- | ---------------------------------------- | 404| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 405| 9300003 | No accessibility permission to perform the operation. | 406 407**示例:** 408 409```ts 410import { AccessibilityElement } from '@kit.AccessibilityKit'; 411import { BusinessError } from '@kit.BasicServicesKit'; 412 413let rootElement: AccessibilityElement; 414 415axContext.getWindowRootElement().then((data: AccessibilityElement) => { 416 rootElement = data; 417 console.log(`Succeeded in get root element of the window, ${JSON.stringify(data)}`); 418}).catch((err: BusinessError) => { 419 console.error(`failed to get root element of the window, Code is ${err.code}, message is ${err.message}`); 420}); 421``` 422 423## AccessibilityExtensionContext.getWindowRootElement<sup>(deprecated)</sup> 424 425getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void; 426 427获取指定窗口的根节点元素, 使用callback异步回调。 428 429> **说明:** 430> 431> 从API version 12开始废弃。 432 433**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 434 435**参数:** 436 437| 参数名 | 类型 | 必填 | 说明 | 438| -------- | ---------------------------------------- | ---- | ------------------ | 439| callback | AsyncCallback<[AccessibilityElement](#accessibilityelement9)> | 是 | 回调函数,返回指定窗口的根节点元素。 | 440 441**错误码:** 442 443以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 444 445| 错误码ID | 错误信息 | 446| ------- | ---------------------------------------- | 447| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 448| 9300003 | No accessibility permission to perform the operation. | 449 450**示例:** 451 452```ts 453import { AccessibilityElement } from '@kit.AccessibilityKit'; 454import { BusinessError } from '@kit.BasicServicesKit'; 455 456let rootElement: AccessibilityElement; 457 458axContext.getWindowRootElement((err: BusinessError, data: AccessibilityElement) => { 459 if (err && err.code) { 460 console.error(`failed to get root element of the window, Code is ${err.code}, message is ${err.message}`); 461 return; 462 } 463 rootElement = data; 464 console.info(`Succeeded in get root element of the window, ${JSON.stringify(data)}`); 465}); 466``` 467 468## AccessibilityExtensionContext.getWindowRootElement<sup>(deprecated)</sup> 469 470getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityElement>): void; 471 472获取指定窗口的根节点元素, 使用callback异步回调。 473 474> **说明:** 475> 476> 从API version 12开始废弃。 477 478**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 479 480**参数:** 481 482| 参数名 | 类型 | 必填 | 说明 | 483| -------- | ---------------------------------------- | ---- | ---------------------- | 484| windowId | number | 是 | 指定窗口的编号,未指定则从当前活跃窗口获取。 | 485| callback | AsyncCallback<[AccessibilityElement](#accessibilityelement9)> | 是 | 回调函数,返回指定窗口的根节点元素。 | 486 487**错误码:** 488 489以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 490 491| 错误码ID | 错误信息 | 492| ------- | ---------------------------------------- | 493| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 494| 9300003 | No accessibility permission to perform the operation. | 495 496**示例:** 497 498```ts 499import { AccessibilityElement } from '@kit.AccessibilityKit'; 500import { BusinessError } from '@kit.BasicServicesKit'; 501 502let windowId = 10; 503let rootElement: AccessibilityElement; 504 505axContext.getWindowRootElement(windowId, (err: BusinessError, data: AccessibilityElement) => { 506 if (err && err.code) { 507 console.error(`failed to get root element of the window, Code is ${err.code}, message is ${err.message}`); 508 return; 509 } 510 rootElement = data; 511 console.info(`Succeeded in get root element of the window, ${JSON.stringify(data)}`); 512}); 513``` 514 515## AccessibilityExtensionContext.getWindows<sup>(deprecated)</sup> 516 517getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>; 518 519获取指定屏幕中的所有窗口, 使用Promise异步回调。 520 521> **说明:** 522> 523> 从API version 12开始废弃。 524 525**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 526 527**参数:** 528 529| 参数名 | 类型 | 必填 | 说明 | 530| --------- | ------ | ---- | --------------------- | 531| displayId | number | 否 | 指定的屏幕编号,未指定则从默认主屏幕获取。 | 532 533**返回值:** 534 535| 类型 | 说明 | 536| ---------------------------------------- | ---------------------- | 537| Promise<Array<[AccessibilityElement](#accessibilityelement9)>> | Promise对象,返回指定屏幕的所有窗口。 | 538 539**错误码:** 540 541以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 542 543| 错误码ID | 错误信息 | 544| ------- | ---------------------------------------- | 545| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 546| 9300003 | No accessibility permission to perform the operation. | 547 548**示例:** 549 550```ts 551import { AccessibilityElement } from '@kit.AccessibilityKit'; 552import { BusinessError } from '@kit.BasicServicesKit'; 553 554axContext.getWindows().then((data: AccessibilityElement[]) => { 555 console.log(`Succeeded in get windows, ${JSON.stringify(data)}`); 556}).catch((err: BusinessError) => { 557 console.error(`failed to get windows, Code is ${err.code}, message is ${err.message}`); 558}); 559``` 560 561## AccessibilityExtensionContext.getWindows<sup>(deprecated)</sup> 562 563getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void; 564 565获取指定屏幕中的所有窗口, 使用callback异步回调。 566 567> **说明:** 568> 569> 从API version 12开始废弃。 570 571**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 572 573**参数:** 574 575| 参数名 | 类型 | 必填 | 说明 | 576| -------- | ---------------------------------------- | ---- | ----------------- | 577| callback | AsyncCallback<Array<[AccessibilityElement](#accessibilityelement9)>> | 是 | 回调函数,返回指定屏幕的所有窗口。 | 578 579**错误码:** 580 581以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 582 583| 错误码ID | 错误信息 | 584| ------- | ---------------------------------------- | 585| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 586| 9300003 | No accessibility permission to perform the operation. | 587 588**示例:** 589 590```ts 591import { AccessibilityElement } from '@kit.AccessibilityKit'; 592import { BusinessError } from '@kit.BasicServicesKit'; 593 594axContext.getWindows((err: BusinessError, data: AccessibilityElement[]) => { 595 if (err && err.code) { 596 console.error(`failed to get windows, Code is ${err.code}, message is ${err.message}`); 597 return; 598 } 599 console.info(`Succeeded in get windows, ${JSON.stringify(data)}`); 600}); 601``` 602 603## AccessibilityExtensionContext.getWindows<sup>(deprecated)</sup> 604 605getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityElement>>): void; 606 607获取指定屏幕中的所有窗口, 使用callback异步回调。 608 609> **说明:** 610> 611> 从API version 12开始废弃。 612 613**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 614 615**参数:** 616 617| 参数名 | 类型 | 必填 | 说明 | 618| --------- | ---------------------------------------- | ---- | --------------------- | 619| displayId | number | 是 | 指定的屏幕编号,未指定则从默认主屏幕获取。 | 620| callback | AsyncCallback<Array<[AccessibilityElement](#accessibilityelement9)>> | 是 | 回调函数,返回指定屏幕的所有窗口。 | 621 622**错误码:** 623 624以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 625 626| 错误码ID | 错误信息 | 627| ------- | ---------------------------------------- | 628| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 629| 9300003 | No accessibility permission to perform the operation. | 630 631**示例:** 632 633```ts 634import { AccessibilityElement } from '@kit.AccessibilityKit'; 635import { BusinessError } from '@kit.BasicServicesKit'; 636 637let displayId = 10; 638axContext.getWindows(displayId, (err: BusinessError, data: AccessibilityElement[]) => { 639 if (err && err.code) { 640 console.error(`failed to get windows, Code is ${err.code}, message is ${err.message}`); 641 return; 642 } 643 console.info(`Succeeded in get windows, ${JSON.stringify(data)}`); 644}); 645``` 646 647## AccessibilityExtensionContext.injectGesture<sup>(deprecated)</sup> 648 649injectGesture(gesturePath: GesturePath): Promise\<void>; 650 651> **说明:** 652> 653> 从API version 10开始废弃。 654 655注入手势,使用Promise异步回调。 656 657**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 658 659**参数:** 660 661| 参数名 | 类型 | 必填 | 说明 | 662| ----------- |--------------------------------------------------------------------| ---- | ---------- | 663| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是 | 表示手势的路径信息。 | 664 665**返回值:** 666 667| 类型 | 说明 | 668| ------------------- | ---------------- | 669| Promise<void> | 无返回结果的Promise对象。 | 670 671**错误码:** 672 673以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 674 675| 错误码ID | 错误信息 | 676| ------- | ---------------------------------------- | 677| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 678| 9300003 | No accessibility permission to perform the operation. | 679 680**示例:** 681 682```ts 683import { GesturePath, GesturePoint } from '@kit.AccessibilityKit'; 684import { BusinessError } from '@kit.BasicServicesKit'; 685 686let gesturePath: GesturePath = new GesturePath(100); 687 688for (let i = 0; i < 10; i++) { 689 let gesturePoint = new GesturePoint(100, i * 200); 690 gesturePath.points.push(gesturePoint); 691} 692axContext.injectGesture(gesturePath).then(() => { 693 console.info(`Succeeded in inject gesture,gesturePath is ${gesturePath}`); 694}).catch((err: BusinessError) => { 695 console.error(`failed to inject gesture, Code is ${err.code}, message is ${err.message}`); 696}); 697``` 698## AccessibilityExtensionContext.injectGesture<sup>(deprecated)</sup> 699 700injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void 701 702> **说明:** 703> 704> 从API version 10开始废弃。 705 706注入手势,使用callback异步回调。 707 708**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 709 710**参数:** 711 712| 参数名 | 类型 | 必填 | 说明 | 713| ----------- |--------------------------------------------------------------------| ---- | ------------------- | 714| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是 | 表示手势的路径信息。 | 715| callback | AsyncCallback<void> | 是 | 回调函数,表示注入手势执行结果的回调。 | 716 717**错误码:** 718 719以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 720 721| 错误码ID | 错误信息 | 722| ------- | ---------------------------------------- | 723| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 724| 9300003 | No accessibility permission to perform the operation. | 725 726**示例:** 727 728```ts 729import { GesturePath, GesturePoint } from '@kit.AccessibilityKit'; 730import { BusinessError } from '@kit.BasicServicesKit'; 731 732let gesturePath: GesturePath = new GesturePath(100); 733for (let i = 0; i < 10; i++) { 734 let gesturePoint = new GesturePoint(100, i * 200); 735 gesturePath.points.push(gesturePoint); 736} 737axContext.injectGesture(gesturePath, (err: BusinessError) => { 738 if (err) { 739 console.error(`failed to inject gesture, Code is ${err.code}, message is ${err.message}`); 740 return; 741 } 742 console.info(`Succeeded in inject gesture,gesturePath is ${gesturePath}`); 743}); 744``` 745## AccessibilityExtensionContext.injectGestureSync<sup>(deprecated)</sup> 746 747injectGestureSync(gesturePath: GesturePath): void 748 749注入手势。 750 751> **说明:** 752> 753> 从API version 12开始废弃。 754 755**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 756 757**参数:** 758 759| 参数名 | 类型 | 必填 | 说明 | 760| ----------- |--------------------------------------------------------------------| ---- | -------------------- | 761| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是 | 表示手势的路径信息。 | 762 763**错误码:** 764 765以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 766 767| 错误码ID | 错误信息 | 768| -------- | --------------------------------------------------- | 769| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 770| 9300003 | No accessibility permission to perform the operation. | 771 772**示例:** 773 774```ts 775import { GesturePath, GesturePoint } from '@kit.AccessibilityKit'; 776 777let gesturePath: GesturePath = new GesturePath(100); 778for (let i = 0; i < 10; i++) { 779 let gesturePoint = new GesturePoint(100, i * 200); 780 gesturePath.points.push(gesturePoint); 781} 782axContext.injectGestureSync(gesturePath); 783``` 784 785## AccessibilityElement<sup>9+</sup> 786 787无障碍节点元素, 在调用AccessibilityElement的方法前,需要先通过[AccessibilityExtensionContext.getFocusElement() ](#accessibilityextensioncontextgetfocuselementdeprecated)或者[AccessibilityExtensionContext.getWindowRootElement() ](#accessibilityextensioncontextgetwindowrootelementdeprecated)获取AccessibilityElement实例。 788 789**系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Core 790 791### attributeNames<sup>(deprecated)</sup> 792 793attributeNames\<T extends keyof ElementAttributeValues>() : Promise\<Array\<T>>; 794 795获取节点元素的所有属性名称,使用Promise异步回调。 796 797> **说明:** 798> 799> 从API version 12开始废弃。 800 801**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 802 803**返回值:** 804 805| 类型 | 说明 | 806| ----------------------------- | ------------------------ | 807| Promise<Array<T>> | Promise对象,返回节点元素的所有属性名称。 | 808 809**示例:** 810 811```ts 812import { ElementAttributeKeys } from '@kit.AccessibilityKit'; 813import { BusinessError } from '@kit.BasicServicesKit'; 814 815// rootElement是AccessibilityElement的实例 816rootElement.attributeNames().then((data: ElementAttributeKeys[]) => { 817 console.log(`Succeeded in get attribute names, ${JSON.stringify(data)}`); 818}).catch((err: BusinessError) => { 819 console.log(`failed to get attribute names, Code is ${err.code}, message is ${err.message}`); 820}); 821``` 822 823### attributeNames<sup>(deprecated)</sup> 824 825attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\<Array\<T>>): void; 826 827获取节点元素的所有属性名称,使用callback异步回调。 828 829> **说明:** 830> 831> 从API version 12开始废弃。 832 833**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 834 835**参数:** 836 837| 参数名 | 类型 | 必填 | 说明 | 838| -------- | ----------------------------------- | ---- | ------------------- | 839| callback | AsyncCallback<Array<T>> | 是 | 回调函数,返回节点元素的所有属性名称。 | 840 841**示例:** 842 843```ts 844import { ElementAttributeKeys } from '@kit.AccessibilityKit'; 845import { BusinessError } from '@kit.BasicServicesKit'; 846 847// rootElement是AccessibilityElement的实例 848rootElement.attributeNames((err: BusinessError, data: ElementAttributeKeys[]) => { 849 if (err && err.code) { 850 console.error(`failed to get attribute names, Code is ${err.code}, message is ${err.message}`); 851 return; 852 } 853 console.info(`Succeeded in get attribute names, ${JSON.stringify(data)}`); 854}); 855``` 856 857### attributeValue<sup>(deprecated)</sup> 858 859attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promise\<ElementAttributeValues[T]>; 860 861根据属性名称获取属性值,使用Promise异步回调。 862 863> **说明:** 864> 865> 从API version 12开始废弃。 866 867**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 868 869 870**参数:** 871 872| 参数名 | 类型 | 必填 | 说明 | 873| ------------- | ---- | ---- | -------- | 874| attributeName | ElementAttributeKeys | 是 | 表示属性的名称。 | 875 876**返回值:** 877 878| 类型 | 说明 | 879| ---------------------------------------- | --------------------------- | 880| Promise<ElementAttributeValues[T]> | Promise对象,返回根据节点属性名称获取的属性值。 | 881 882**错误码:** 883 884以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 885 886| 错误码ID | 错误信息 | 887| ------- | ----------------------------- | 888| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 889| 9300004 | This property does not exist. | 890 891 892**示例:** 893 894```ts 895import { ElementAttributeKeys } from '@kit.AccessibilityKit'; 896import { BusinessError } from '@kit.BasicServicesKit'; 897 898let attributeName: ElementAttributeKeys = 'bundleName'; 899 900// rootElement是AccessibilityElement的实例 901rootElement.attributeValue(attributeName).then((data: string) => { 902 console.log(`Succeeded in get attribute value by name, ${JSON.stringify(data)}`); 903}).catch((err: BusinessError) => { 904 console.error(`failed to get attribute value, Code is ${err.code}, message is ${err.message}`); 905}); 906``` 907 908### attributeValue<sup>(deprecated)</sup> 909 910attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T, 911 callback: AsyncCallback\<ElementAttributeValues[T]>): void; 912 913根据属性名称获取属性值,使用callback异步回调。 914 915> **说明:** 916> 917> 从API version 12开始废弃。 918 919**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 920 921**参数:** 922 923| 参数名 | 类型 | 必填 | 说明 | 924| ------------- | ---------------------------------------- | ---- | ---------------------- | 925| attributeName | ElementAttributeKeys | 是 | 表示属性的名称。 | 926| callback | AsyncCallback<ElementAttributeValues[T]> | 是 | 回调函数,返回根据节点属性名称获取的属性值。 | 927 928**错误码:** 929 930以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 931 932| 错误码ID | 错误信息 | 933| ------- | ----------------------------- | 934| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 935| 9300004 | This property does not exist. | 936 937**示例:** 938 939```ts 940import { ElementAttributeKeys } from '@kit.AccessibilityKit'; 941import { BusinessError } from '@kit.BasicServicesKit'; 942 943let attributeName: ElementAttributeKeys = 'bundleName'; 944 945// rootElement是AccessibilityElement的实例 946rootElement.attributeValue(attributeName, (err: BusinessError, data: string) => { 947 if (err && err.code) { 948 console.error(`failed to get attribute value, Code is ${err.code}, message is ${err.message}`); 949 return; 950 } 951 console.info(`Succeeded in get attribute value, ${JSON.stringify(data)}`); 952}); 953``` 954 955### actionNames<sup>(deprecated)</sup> 956 957actionNames(): Promise\<Array\<string>>; 958 959获取节点元素支持的所有操作名称,使用Promise异步回调。 960 961> **说明:** 962> 963> 从API version 12开始废弃。 964 965**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 966 967**返回值:** 968 969| 类型 | 说明 | 970| ---------------------------------- | -------------------------- | 971| Promise<Array<string>> | Promise对象,返回节点元素支持的所有操作名称。 | 972 973**示例:** 974 975```ts 976import { BusinessError } from '@kit.BasicServicesKit'; 977 978// rootElement是AccessibilityElement的实例 979rootElement.actionNames().then((data: string[]) => { 980 console.log(`Succeeded in get action names, ${JSON.stringify(data)}`); 981}).catch((err: BusinessError) => { 982 console.error(`failed to get action names, Code is ${err.code}, message is ${err.message}`); 983}) 984``` 985 986### actionNames<sup>(deprecated)</sup> 987 988actionNames(callback: AsyncCallback\<Array\<string>>): void; 989 990获取节点元素支持的所有操作名称,使用callback异步回调。 991 992> **说明:** 993> 994> 从API version 12开始废弃。 995 996**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 997 998**参数:** 999 1000| 参数名 | 类型 | 必填 | 说明 | 1001| -------- | ---------------------------------------- | ---- | --------------------- | 1002| callback | AsyncCallback<Array<string>> | 是 | 回调函数,返回节点元素支持的所有操作名称。 | 1003 1004**示例:** 1005 1006```ts 1007// rootElement是AccessibilityElement的实例 1008rootElement.actionNames((err: BusinessError, data: string[]) => { 1009 if (err && err.code) { 1010 console.error(`failed to get action names, Code is ${err.code}, message is ${err.message}`); 1011 return; 1012 } 1013 console.info(`Succeeded in get action names, ${JSON.stringify(data)}`); 1014}) 1015``` 1016 1017### performAction<sup>(deprecated)</sup> 1018 1019performAction(actionName: string, parameters?: object): Promise\<void>; 1020 1021根据操作名称执行某个操作,使用Promise异步回调。 1022 1023> **说明:** 1024> 1025> 从API version 12开始废弃。 1026 1027**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1028 1029**参数:** 1030 1031| 参数名 | 类型 | 必填 | 说明 | 1032| ----------- | ---------------------------------------- | ---- |----------------------------------------------------------| 1033| actionName | string | 是 | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。 1034| parameters | object | 否 | 表示执行操作时所需要的参数;默认为空。 | 1035 1036**返回值:** 1037 1038| 类型 | 说明 | 1039| ------------------- | ---------------- | 1040| Promise<void> | 无返回结果的Promise对象。 | 1041 1042**错误码:** 1043 1044以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1045 1046| 错误码ID | 错误信息 | 1047| ------- | ----------------------------- | 1048| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1049| 9300005 | This action is not supported. | 1050 1051**示例:** 1052 1053```ts 1054import { BusinessError } from '@kit.BasicServicesKit'; 1055 1056let actionName = 'action'; 1057 1058// rootElement是AccessibilityElement的实例 1059rootElement.performAction(actionName).then(() => { 1060 console.info(`Succeeded in perform action,actionName is ${actionName}`); 1061}).catch((err: BusinessError) => { 1062 console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`); 1063}); 1064``` 1065 1066**无参数Action示例:** 1067 1068```ts 1069import { BusinessError } from '@kit.BasicServicesKit'; 1070 1071// rootElement是AccessibilityElement的实例 1072// Action描述中无明确要求的,均为无参数Action 1073rootElement.performAction('click').then(() => { 1074 console.info(`Succeeded in perform action.`); 1075}).catch((err: BusinessError) => { 1076 console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`); 1077}); 1078``` 1079 1080**有参数Action示例:** 1081 1082```ts 1083import { BusinessError } from '@kit.BasicServicesKit'; 1084 1085// rootElement是AccessibilityElement的实例 1086// setSelection示例代码 1087rootElement.performAction('setSelection', { 1088 selectTextBegin: '0', // 表示选择起始位置 1089 selectTextEnd: '8', // 表示选择结束位置 1090 selectTextInForWard: true // true表示为前光标,false表示为后光标 1091}).then(() => { 1092 console.info(`Succeeded in perform action`); 1093}).catch((err: BusinessError) => { 1094 console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`); 1095}); 1096``` 1097 1098```ts 1099import { BusinessError } from '@kit.BasicServicesKit'; 1100 1101// rootElement是AccessibilityElement的实例 1102// setCursorPosition示例代码 1103rootElement.performAction('setCursorPosition', { 1104 offset: '1' // 表示光标的设置位置 1105}).then(() => { 1106 console.info(`Succeeded in perform action`); 1107}).catch((err: BusinessError) => { 1108 console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`); 1109}); 1110``` 1111 1112### performAction<sup>(deprecated)</sup> 1113 1114performAction(actionName: string, callback: AsyncCallback\<void>): void; 1115 1116根据操作名称执行某个操作,使用callback异步回调。 1117 1118> **说明:** 1119> 1120> 从API version 12开始废弃。 1121 1122**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1123 1124**参数:** 1125 1126| 参数名 | 类型 | 必填 | 说明 | 1127| ----------- | ---------------------------------------- | ---- | -------------- | 1128| actionName | string | 是 | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。 1129| callback | AsyncCallback<void> | 是 | 回调函数,表示执行指定操作的回调。| 1130 1131**错误码:** 1132 1133以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1134 1135| 错误码ID | 错误信息 | 1136| ------- | ----------------------------- | 1137| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1138| 9300005 | This action is not supported. | 1139 1140**示例:** 1141 1142```ts 1143import { BusinessError } from '@kit.BasicServicesKit'; 1144 1145let actionName = 'action'; 1146 1147// rootElement是AccessibilityElement的实例 1148rootElement.performAction(actionName, (err: BusinessError) => { 1149 if (err && err.code) { 1150 console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`); 1151 return; 1152 } 1153 console.info(`Succeeded in perform action, actionName is ${actionName}`); 1154}); 1155``` 1156 1157### performAction<sup>(deprecated)</sup> 1158 1159performAction(actionName: string, parameters: object, callback: AsyncCallback\<void>): void; 1160 1161根据操作名称执行某个操作,使用callback异步回调。 1162 1163> **说明:** 1164> 1165> 从API version 12开始废弃。 1166 1167**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1168 1169**参数:** 1170 1171| 参数名 | 类型 | 必填 | 说明 | 1172| ---------- | ------------------------- | ---- |-------------------------------------------------------------| 1173| actionName | string | 是 | 表示属性的名称,取值参考[Action](./js-apis-accessibility.md#action)。 | 1174| parameters | object | 是 | 表示执行操作时所需要的参数;默认为空。 | 1175| callback | AsyncCallback<void> | 是 | 回调函数,表示执行指定操作的回调。 | 1176 1177**错误码:** 1178 1179以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1180 1181| 错误码ID | 错误信息 | 1182| ------- | ----------------------------- | 1183| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1184| 9300005 | This action is not supported. | 1185 1186**示例:** 1187 1188```ts 1189import { BusinessError } from '@kit.BasicServicesKit'; 1190 1191let actionName = 'action'; 1192let parameters: object = []; 1193 1194// rootElement是AccessibilityElement的实例 1195rootElement.performAction(actionName, parameters, (err: BusinessError) => { 1196 if (err && err.code) { 1197 console.error(`failed to perform action, Code is ${err.code}, message is ${err.message}`); 1198 return; 1199 } 1200 console.info(`Succeeded in perform action,actionName is ${actionName}, parameters is ${parameters}`); 1201}); 1202``` 1203 1204### findElement('content')<sup>(deprecated)</sup> 1205 1206findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>; 1207 1208根据节点内容查询所有节点元素,使用Promise异步回调。 1209 1210> **说明:** 1211> 1212> 从API version 12开始废弃。 1213 1214**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1215 1216**参数:** 1217 1218| 参数名 | 类型 | 必填 | 说明 | 1219| --------- | ------ | ---- | ----------------------------- | 1220| type | string | 是 | 固定为'content', 表示查找的类型为节点元素内容。 | 1221| condition | string | 是 | 表示查找的条件。 | 1222 1223**返回值:** 1224 1225| 类型 | 说明 | 1226| ---------------------------------------- | ----------------------------- | 1227| Promise<Array<[AccessibilityElement](#accessibilityelement9)>> | Promise对象,返回满足指定查询关键字的所有节点元素。 | 1228 1229**错误码:** 1230 1231以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1232 1233| 错误码ID | 错误信息 | 1234| ------- | ----------------------------- | 1235| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1236 1237**示例:** 1238 1239```ts 1240import { BusinessError } from '@kit.BasicServicesKit'; 1241 1242let condition = 'keyword'; 1243 1244// rootElement是AccessibilityElement的实例 1245rootElement.findElement('content', condition).then((data: AccessibilityElement[]) => { 1246 console.log(`Succeeded in find element, ${JSON.stringify(data)}`); 1247}).catch((err: BusinessError) => { 1248 console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 1249}); 1250``` 1251 1252### findElement('content')<sup>(deprecated)</sup> 1253 1254findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<AccessibilityElement>>): void; 1255 1256根据节点内容查询所有节点元素。 1257 1258> **说明:** 1259> 1260> 从API version 12开始废弃。 1261 1262**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1263 1264**参数:** 1265 1266| 参数名 | 类型 | 必填 | 说明 | 1267| --------- | ---------------------------------------- | ---- | ---------------------------- | 1268| type | string | 是 | 固定为'content',表示查找的类型为节点元素内容。 | 1269| condition | string | 是 | 表示查找的条件。 | 1270| callback | AsyncCallback<Array<[AccessibilityElement](#accessibilityelement9)>> | 是 | 回调函数,返回满足指定查询关键字的所有节点元素。 | 1271 1272**错误码:** 1273 1274以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1275 1276| 错误码ID | 错误信息 | 1277| ------- | ----------------------------- | 1278| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1279 1280**示例:** 1281 1282```ts 1283import { BusinessError } from '@kit.BasicServicesKit'; 1284 1285let condition = 'keyword'; 1286 1287// rootElement是AccessibilityElement的实例 1288rootElement.findElement('content', condition, (err: BusinessError, data: AccessibilityElement[])=>{ 1289 if (err && err.code) { 1290 console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 1291 return; 1292 } 1293 console.info(`Succeeded in find element, ${JSON.stringify(data)}`); 1294}); 1295``` 1296 1297### findElement('focusType')<sup>(deprecated)</sup> 1298 1299findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>; 1300 1301根据焦点元素类型查询节点元素,使用Promise异步回调。 1302 1303> **说明:** 1304> 1305> 从API version 12开始废弃。 1306 1307**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1308 1309**参数:** 1310 1311| 参数名 | 类型 | 必填 | 说明 | 1312| --------- | ----------------------- | ---- | ---------------------------------- | 1313| type | string | 是 | 固定为'focusType', 表示查询的类型为节点的焦点元素类型。 | 1314| condition | [FocusType](#focustype) | 是 | 表示查询焦点元素的类型。 | 1315 1316**返回值:** 1317 1318| 类型 | 说明 | 1319| ----------------------------------- | ------------------------------ | 1320| Promise<[AccessibilityElement](#accessibilityelement9)> | Promise对象,返回满足指定查询焦点元素类型的节点元素。 | 1321 1322**错误码:** 1323 1324以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1325 1326| 错误码ID | 错误信息 | 1327| ------- | ----------------------------- | 1328| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1329 1330**示例:** 1331 1332```ts 1333import { FocusType } from '@kit.AccessibilityKit'; 1334import { BusinessError } from '@kit.BasicServicesKit'; 1335 1336let condition: FocusType = 'normal'; 1337 1338// rootElement是AccessibilityElement的实例 1339rootElement.findElement('focusType', condition).then((data: AccessibilityElement) => { 1340 console.log(`Succeeded in find element,${JSON.stringify(data)}`); 1341}).catch((err: BusinessError) => { 1342 console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 1343}); 1344``` 1345 1346### findElement('focusType')<sup>(deprecated)</sup> 1347 1348findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void; 1349 1350根据焦点元素类型查询节点元素,使用callback异步回调。 1351 1352> **说明:** 1353> 1354> 从API version 12开始废弃。 1355 1356**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1357 1358**参数:** 1359 1360| 参数名 | 类型 | 必填 | 说明 | 1361| --------- | ---------------------------------------- | ---- | ---------------------------------- | 1362| type | string | 是 | 固定为'focusType', 表示查询的类型为节点的焦点元素类型。 | 1363| condition | [FocusType](#focustype) | 是 | 表示查询焦点元素的类型。 | 1364| callback | AsyncCallback<[AccessibilityElement](#accessibilityelement9)> | 是 | 回调函数,返回满足指定查询焦点元素类型的节点元素。 | 1365 1366**错误码:** 1367 1368以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1369 1370| 错误码ID | 错误信息 | 1371| ------- | ----------------------------- | 1372| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1373 1374**示例:** 1375 1376```ts 1377import { FocusType } from '@kit.AccessibilityKit'; 1378import { BusinessError } from '@kit.BasicServicesKit'; 1379 1380let condition: FocusType = 'normal'; 1381 1382// rootElement是AccessibilityElement的实例 1383rootElement.findElement('focusType', condition, (err: BusinessError, data: AccessibilityElement)=>{ 1384 if (err && err.code) { 1385 console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 1386 return; 1387 } 1388 console.info(`Succeeded in find element, ${JSON.stringify(data)}`); 1389}); 1390``` 1391 1392### findElement('focusDirection')<sup>(deprecated)</sup> 1393 1394findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>; 1395 1396根据下一焦点元素方向查询节点元素,使用Promise异步回调。 1397 1398> **说明:** 1399> 1400> 从API version 12开始废弃。 1401 1402**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1403 1404**参数:** 1405 1406| 参数名 | 类型 | 必填 | 说明 | 1407| --------- | --------------------------------- | ---- | ---------------------------------------- | 1408| type | string | 是 | 固定为'focusDirection', 表示查询的类型为节点的下一焦点元素方向。 | 1409| condition | [FocusDirection](#focusdirection) | 是 | 表示查询下一焦点元素的方向。 | 1410 1411**返回值:** 1412 1413| 类型 | 说明 | 1414| ----------------------------------- | -------------------------------- | 1415| Promise<[AccessibilityElement](#accessibilityelement9)> | Promise对象,返回满足指定查询下一焦点元素方向的节点元素。 | 1416 1417**错误码:** 1418 1419以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1420 1421| 错误码ID | 错误信息 | 1422| ------- | ----------------------------- | 1423| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1424 1425**示例:** 1426 1427```ts 1428import { FocusDirection } from '@kit.AccessibilityKit'; 1429import { BusinessError } from '@kit.BasicServicesKit'; 1430 1431let condition: FocusDirection = 'up'; 1432 1433// rootElement是AccessibilityElement的实例 1434rootElement.findElement('focusDirection', condition).then((data: AccessibilityElement) => { 1435 console.log(`Succeeded in find element, ${JSON.stringify(data)}`); 1436}).catch((err: BusinessError) => { 1437 console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 1438}); 1439``` 1440 1441### findElement('focusDirection')<sup>(deprecated)</sup> 1442 1443findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void; 1444 1445根据下一焦点元素方向查询节点元素,使用callback异步回调。 1446 1447> **说明:** 1448> 1449> 从API version 12开始废弃。 1450 1451**系统能力**:SystemCapability.BarrierFree.Accessibility.Core 1452 1453**参数:** 1454 1455| 参数名 | 类型 | 必填 | 说明 | 1456| --------- | ---------------------------------------- | ---- | ---------------------------------------- | 1457| type | string | 是 | 固定为'focusDirection', 表示查询的类型为节点的下一焦点元素方向。 | 1458| condition | [FocusDirection](#focusdirection) | 是 | 表示下一查询焦点元素的方向。 | 1459| callback | AsyncCallback<[AccessibilityElement](#accessibilityelement9)> | 是 | 回调函数,返回满足指定查询下一焦点元素方向的节点元素。 | 1460 1461**错误码:** 1462 1463以下错误码的详细介绍请参见[无障碍子系统错误码](errorcode-accessibility.md)。 1464 1465| 错误码ID | 错误信息 | 1466| ------- | ----------------------------- | 1467| 401 |Input parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1468 1469**示例:** 1470 1471```ts 1472import { FocusDirection } from '@kit.AccessibilityKit'; 1473import { BusinessError } from '@kit.BasicServicesKit'; 1474 1475let condition: FocusDirection = 'up'; 1476 1477// rootElement是AccessibilityElement的实例 1478rootElement.findElement('focusDirection', condition, (err: BusinessError, data: AccessibilityElement) =>{ 1479 if (err && err.code) { 1480 console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 1481 return; 1482 } 1483 console.info(`Succeeded in find element, ${JSON.stringify(data)}`); 1484}); 1485```