1e41f4b71Sopenharmony_ci# AccessibilityExtensionContext (System API) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe **AccessibilityExtensionContext** module, inherited from **ExtensionContext**, provides context for **AccessibilityExtensionAbility**. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciYou can use the APIs of this module to configure the concerned information, obtain root information, and inject gestures. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci> **NOTE** 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 10e41f4b71Sopenharmony_ci> - The current page contains only the system APIs of the current module. For details about other public APIs, see [AccessibilityExtensionContext](js-apis-inner-application-accessibilityExtensionContext.md). 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## Instructions 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciBefore using the **AccessibilityExtensionContext** module, you must define a child class that inherits from **AccessibilityExtensionAbility**. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci```ts 17e41f4b71Sopenharmony_ciimport { AccessibilityExtensionAbility } from '@kit.AccessibilityKit'; 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciclass EntryAbility extends AccessibilityExtensionAbility { 20e41f4b71Sopenharmony_ci onConnect(): void { 21e41f4b71Sopenharmony_ci let axContext = this.context; 22e41f4b71Sopenharmony_ci } 23e41f4b71Sopenharmony_ci} 24e41f4b71Sopenharmony_ci``` 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci### enableScreenCurtain<sup>12+</sup> 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_cienableScreenCurtain(isEnable: boolean): void; 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ciEnables or disables the screen curtain. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BarrierFree.Accessibility.Core 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**Parameters** 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 37e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | -------------- | 38e41f4b71Sopenharmony_ci| isEnable | boolean | Yes | **true** indicates enabled; **false** indicates disabled.| 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Error codes** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ciFor details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci| ID | Error Message | 45e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 46e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 47e41f4b71Sopenharmony_ci| 9300003 | No accessibility permission to perform the operation. | 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**Example** 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci```ts 52e41f4b71Sopenharmony_ciimport { AccessibilityElement } from '@kit.AccessibilityKit'; 53e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_cilet rootElement: AccessibilityElement; 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ciaxContext.getWindowRootElement().then((data: AccessibilityElement) => { 58e41f4b71Sopenharmony_ci rootElement = data; 59e41f4b71Sopenharmony_ci console.log(`Succeeded in get root element of the window, ${JSON.stringify(data)}`); 60e41f4b71Sopenharmony_ci await rootElement.enableScreenCurtain(true); 61e41f4b71Sopenharmony_ci console.log(`Succeeded in enableScreenCurtain}`); 62e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 63e41f4b71Sopenharmony_ci console.error(`failed to enableScreenCurtain, Code is ${err.code}, message is ${err.message}`); 64e41f4b71Sopenharmony_ci}); 65e41f4b71Sopenharmony_ci``` 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci### findElement('elementId')<sup>12+</sup> 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_cifindElement(type: 'elementId', condition: number): Promise\<AccessibilityElement>; 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ciQueries the node elements in the current active window based on the **elementId**. This API uses a promise to return the result. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BarrierFree.Accessibility.Core 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci**Parameters** 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 78e41f4b71Sopenharmony_ci| --------- | --------------------------------- | ---- | ---------------------------------------- | 79e41f4b71Sopenharmony_ci| type | string | Yes | Type of element finding. The value is fixed at **'elementId'**.| 80e41f4b71Sopenharmony_ci| condition | number | Yes | **elementId** of the node element. | 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci**Return value** 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci| Type | Description | 85e41f4b71Sopenharmony_ci| ----------------------------------- | -------------------------------- | 86e41f4b71Sopenharmony_ci| Promise<[AccessibilityElement](js-apis-inner-application-accessibilityExtensionContext.md#accessibilityelement9)> | Promise used to return the result.| 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**Error codes** 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ciFor details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci| ID | Error Message | 93e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 94e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci**Example** 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci```ts 99e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci// elementId is 10. 102e41f4b71Sopenharmony_cilet condition = 10; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci// rootElement is an instance of AccessibilityElement. 105e41f4b71Sopenharmony_cirootElement.findElement('elementId', condition).then((data: AccessibilityElement) => { 106e41f4b71Sopenharmony_ci console.log(`Succeeded in find element, ${JSON.stringify(data)}`); 107e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 108e41f4b71Sopenharmony_ci console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 109e41f4b71Sopenharmony_ci}); 110e41f4b71Sopenharmony_ci``` 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci### findElement('textType')<sup>12+</sup> 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_cifindElement(type: 'textType', condition: string): Promise\<Array\<AccessibilityElement>>; 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ciQueries all node elements based on the **accessibilityTextHint** text type configured for a node. This API uses a promise to return the result. 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BarrierFree.Accessibility.Core 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**Parameters** 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 123e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ----------------------------- | 124e41f4b71Sopenharmony_ci| type | string | Yes | Type of element finding. The value is fixed at **'textType'**.| 125e41f4b71Sopenharmony_ci| condition | string | Yes | Search criteria. | 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**Return value** 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci| Type | Description | 130e41f4b71Sopenharmony_ci| ---------------------------------------- | ----------------------------- | 131e41f4b71Sopenharmony_ci| Promise<Array<[AccessibilityElement](js-apis-inner-application-accessibilityExtensionContext.md#accessibilityelement9)>> | Promise used to return the result.| 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**Error codes** 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ciFor details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci| ID | Error Message | 138e41f4b71Sopenharmony_ci| ------- | ----------------------------- | 139e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci**Example** 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci```ts 144e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci// The content of condition must be the same as the type value in the accessibilityTextHint attribute of the target component. 147e41f4b71Sopenharmony_cilet condition = 'location'; 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci// rootElement is an instance of AccessibilityElement. 150e41f4b71Sopenharmony_cirootElement.findElement('textType', condition).then((data: AccessibilityElement[]) => { 151e41f4b71Sopenharmony_ci console.log(`Succeeded in find element, ${JSON.stringify(data)}`); 152e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 153e41f4b71Sopenharmony_ci console.error(`failed to find element, Code is ${err.code}, message is ${err.message}`); 154e41f4b71Sopenharmony_ci}); 155e41f4b71Sopenharmony_ci``` 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci### getCursorPosition<sup>12+</sup> 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_cigetCursorPosition(): Promise\<number>; 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ciObtains the cursor position in the **Text** component. This API uses a promise to return the result. 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BarrierFree.Accessibility.Core 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**Return value** 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci| Type | Description | 168e41f4b71Sopenharmony_ci| ------------------- | ---------------- | 169e41f4b71Sopenharmony_ci| Promise<number> | Promise used to return the result.| 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**Example** 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci```ts 174e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci// rootElement is an instance of AccessibilityElement. 177e41f4b71Sopenharmony_cirootElement.getCursorPosition().then((data: number) => { 178e41f4b71Sopenharmony_ci console.info(`Succeeded in getCursorPosition, ${data}`); 179e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 180e41f4b71Sopenharmony_ci console.error(`failed to getCursorPosition, Code is ${err.code}, message is ${err.message}`); 181e41f4b71Sopenharmony_ci}); 182e41f4b71Sopenharmony_ci``` 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci### getCursorPosition<sup>12+</sup> 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_cigetCursorPosition(callback: AsyncCallback\<number>): void; 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ciObtains the cursor position in the **Text** component. This API uses an asynchronous callback to return the result. 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BarrierFree.Accessibility.Core 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**Parameters** 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 195e41f4b71Sopenharmony_ci| ----------- | ---------------------------------------- | ---- | -------------- | 196e41f4b71Sopenharmony_ci| callback | AsyncCallback<number> | Yes | Callback function used to return the result.| 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**Example** 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci```ts 201e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci// rootElement is an instance of AccessibilityElement. 204e41f4b71Sopenharmony_cirootElement.getCursorPosition((err: BusinessError, data: number) => { 205e41f4b71Sopenharmony_ci if (err && err.code) { 206e41f4b71Sopenharmony_ci console.error(`failed to getCursorPosition, Code is ${err.code}, message is ${err.message}`); 207e41f4b71Sopenharmony_ci return; 208e41f4b71Sopenharmony_ci } 209e41f4b71Sopenharmony_ci console.info(`Succeeded in getCursorPosition, ${data}`); 210e41f4b71Sopenharmony_ci}); 211e41f4b71Sopenharmony_ci``` 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci### startAbility<sup>12+</sup> 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_cistartAbility(want: Want): void; 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ciStarts the foreground page. 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**System capability**: SystemCapability.BarrierFree.Accessibility.Core 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci**Parameters** 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description| 224e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 225e41f4b71Sopenharmony_ci| want | [Want](../../reference/apis-ability-kit/js-apis-app-ability-want.md) | Yes| Want information about the target ability, such as the ability name and bundle name.| 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci**Error codes** 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ciFor details about the error codes, see [Accessibility Error Codes](errorcode-accessibility.md). 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci| ID | Error Message | 232e41f4b71Sopenharmony_ci| ------- | ---------------------------------------- | 233e41f4b71Sopenharmony_ci| 201 | Permission denied. Interface caller does not have permission. | 234e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci**Example** 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci```ts 239e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_cilet want: Want = { 242e41f4b71Sopenharmony_ci bundleName: 'com.huawei.hmos.photos' 243e41f4b71Sopenharmony_ci abilityName: 'com.huawei.hmos.photos.MainAbility' 244e41f4b71Sopenharmony_ci} 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ciaxContext.startAbility(want).then(() => { 247e41f4b71Sopenharmony_ci console.info(`startAbility Succeeded enable ability`); 248e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 249e41f4b71Sopenharmony_ci console.error(`startAbility failed to enable ability, Code is ${err.code}, message is ${err.message}`); 250e41f4b71Sopenharmony_ci}); 251e41f4b71Sopenharmony_ci``` 252