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