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