js-apis-accessibility-config.md 14.3 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.accessibility.config (System Accessibility Configuration)
E
ester.zhou 已提交
2

E
esterzhou 已提交
3
The System Accessibility Configuration module allows you to configure system accessibility features, including accessibility extension, high-contrast text, mouse buttons, and captions.
E
ester.zhou 已提交
4 5 6

> **NOTE**
>
E
esterzhou 已提交
7 8
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs.
E
ester.zhou 已提交
9 10 11

## Modules to Import

E
esterzhou 已提交
12 13
```ts
import config from '@ohos.accessibility.config';
E
ester.zhou 已提交
14 15 16 17 18 19 20 21 22 23
```

## Attributes

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| highContrastText | [Config](#config)\<boolean>| Yes| Yes| Whether to enable high-contrast text.|
| invertColor | [Config](#config)\<boolean>| Yes| Yes| Whether to enable color inversion.|
E
esterzhou 已提交
24
| daltonizationColorFilter | [Config](#config)&lt;[DaltonizationColorFilter](#daltonizationcolorfilter)&gt;| Yes| Yes| Configuration of the daltonization filter.|
E
ester.zhou 已提交
25
| contentTimeout | [Config](#config)\<number>| Yes| Yes| Recommended duration for content display. The value ranges from 0 to 5000, in milliseconds.|
E
esterzhou 已提交
26
| animationOff | [Config](#config)\<boolean>| Yes| Yes| Whether to disable animation.|
E
ester.zhou 已提交
27 28
| brightnessDiscount | [Config](#config)\<number>| Yes| Yes| Brightness discount. The value ranges from 0 to 1.0.|
| mouseKey | [Config](#config)\<boolean>| Yes| Yes| Whether to enable the mouse button feature.|
E
esterzhou 已提交
29
| mouseAutoClick | [Config](#config)\<number>| Yes| Yes| Interval for automatic mouse clicks. The value ranges from 0 to 5000, in milliseconds.|
E
ester.zhou 已提交
30
| shortkey | [Config](#config)\<boolean>| Yes| Yes| Whether to enable the accessibility extension shortcut key.|
E
esterzhou 已提交
31
| shortkeyTarget | [Config](#config)\<string>| Yes| Yes| Target application for the accessibility extension shortcut key. The value format is 'bundleName/abilityName'.|
E
ester.zhou 已提交
32
| captions | [Config](#config)\<boolean>| Yes| Yes| Whether to enable captions.|
E
esterzhou 已提交
33
| captionsStyle | [Config](#config)\<[accessibility.CaptionsStyle](js-apis-accessibility.md#captionsstyle8)>| Yes| Yes| Captions style.|
E
ester.zhou 已提交
34 35 36

## enableAbility

E
esterzhou 已提交
37
enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;): Promise&lt;void&gt;;
E
ester.zhou 已提交
38 39 40 41 42 43 44 45 46

Enables an accessibility extension ability. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
47 48
| name | string | Yes| Name of the accessibility extension ability. The format is 'bundleName/abilityName'.|
| capability | Array&lt;[accessibility.Capability](js-apis-accessibility.md#capability)&gt; | Yes| Capability of the accessibility extension ability.|
E
ester.zhou 已提交
49 50 51 52 53

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
54 55 56 57 58 59 60 61 62 63
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

| ID| Error Message|
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name.  |
| 9300002 | Target ability already enabled. |
E
ester.zhou 已提交
64 65 66

**Example**

E
esterzhou 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80
```ts
import accessibility from '@ohos.accessibility';
let name = 'com.ohos.example/axExtension';
let capability : accessibility.Capability[] = ['retrieve'];
try {
    config.enableAbility(name, capability).then(() => {
      console.info('enable ability succeed');
    }).catch((err) => {
      console.error('failed to enable ability, because ' + JSON.stringify(err));
    });
} catch (exception) {
    console.error('failed to enable ability, because ' + JSON.stringify(exception));
};
```
E
ester.zhou 已提交
81 82 83

## enableAbility

E
esterzhou 已提交
84
enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, callback: AsyncCallback&lt;void&gt;): void;
E
ester.zhou 已提交
85 86 87 88 89 90 91 92 93

Enables an accessibility extension ability. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
94 95 96 97 98 99 100 101 102 103 104 105
| name | string | Yes| Name of the accessibility extension ability. The format is 'bundleName/abilityName'.|
| capability | Array&lt;[accessibility.Capability](js-apis-accessibility.md#capability)&gt; | Yes| Capability of the accessibility extension ability.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

| ID| Error Message|
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name.  |
| 9300002 | Target ability already enabled. |
E
ester.zhou 已提交
106 107 108

**Example**

E
esterzhou 已提交
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
```ts
import accessibility from '@ohos.accessibility';
let name = 'com.ohos.example/axExtension';
let capability : accessibility.Capability[] = ['retrieve'];
try {
    config.enableAbility(name, capability, (err) => {
        if (err) {
            console.error('failed to enable ability, because ' + JSON.stringify(err));
            return;
        }
        console.info('enable ability succeed');
    });
} catch (exception) {
    console.error('failed to enable ability, because ' + JSON.stringify(exception));
};
```
E
ester.zhou 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137

## disableAbility

disableAbility(name: string): Promise&lt;void&gt;;

Disables an accessibility extension ability. This API uses a promise to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
138
| name | string | Yes| Name of the accessibility extension ability. The format is 'bundleName/abilityName'.|
E
ester.zhou 已提交
139 140 141 142 143

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
144 145 146 147 148 149 150 151 152
| Promise&lt;void&gt; | Promise that returns no value.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

| ID| Error Message|
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name.  |
E
ester.zhou 已提交
153 154 155

**Example**

E
esterzhou 已提交
156 157 158 159 160 161 162 163 164 165 166 167
```ts
let name = 'com.ohos.example/axExtension';
try {
    config.disableAbility(name).then(() => {
      console.info('disable ability succeed');
    }).catch((err) => {
      console.error('failed to disable ability, because ' + JSON.stringify(err));
    });
} catch (exception) {
    console.error('failed to disable ability, because ' + JSON.stringify(exception));
};
```
E
ester.zhou 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180

## disableAbility

disableAbility(name: string, callback: AsyncCallback&lt;void&gt;): void;

Disables an accessibility extension ability. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
181 182 183 184 185 186 187 188 189 190
| name | string | Yes| Name of the accessibility extension ability. The format is 'bundleName/abilityName'.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|

**Error codes**

For details about the error codes, see [Accessibility Error Codes](../errorcodes/errorcode-accessibility.md).

| ID| Error Message|
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name.  |
E
ester.zhou 已提交
191 192 193

**Example**

E
esterzhou 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207
```ts
let name = 'com.ohos.example/axExtension';
try {
    config.disableAbility(name, (err, data) => {
        if (err) {
            console.error('failed to enable ability, because ' + JSON.stringify(err));
            return;
        }
        console.info('disable succeed');
    });
} catch (exception) {
    console.error('failed to enable ability, because ' + JSON.stringify(exception));
};
```
E
ester.zhou 已提交
208

E
esterzhou 已提交
209
## on('enabledAccessibilityExtensionListChange')
E
ester.zhou 已提交
210

E
esterzhou 已提交
211
on(type: 'enabledAccessibilityExtensionListChange', callback: Callback&lt;void&gt;): void;
E
ester.zhou 已提交
212

E
esterzhou 已提交
213
Adds a listener for changes in the list of enabled accessibility extension abilities. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
214 215 216 217 218 219 220

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
221
| type | string | Yes| Listening type. The value is fixed at **'enabledAccessibilityExtensionListChange'**, indicating listening for changes in the list of enabled accessibility extension abilities.|
E
ester.zhou 已提交
222 223 224 225
| callback | Callback&lt;void&gt; | Yes| Callback invoked when the list of enabled accessibility extension abilities changes.|

**Example**

E
esterzhou 已提交
226 227 228 229 230 231 232 233 234 235
```ts
try {
    config.on('enabledAccessibilityExtensionListChange', () => {
        console.info('subscribe enabled accessibility extension list change state success');
    });
} catch (exception) {
    console.error('failed to subscribe enabled accessibility extension list change state, because ' +
    JSON.stringify(exception));
};
```
E
ester.zhou 已提交
236

E
esterzhou 已提交
237
## off('enabledAccessibilityExtensionListChange')
E
ester.zhou 已提交
238

E
esterzhou 已提交
239
off(type: 'enabledAccessibilityExtensionListChange', callback?: Callback&lt;void&gt;): void;
E
ester.zhou 已提交
240

E
esterzhou 已提交
241
Cancels the listener for changes in the list of enabled accessibility extension abilities. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
242 243 244 245 246 247 248

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
249
| type |  string | Yes| Listening type. The value is fixed at **'enabledAccessibilityExtensionListChange'**, indicating listening for changes in the list of enabled accessibility extension abilities.|
E
ester.zhou 已提交
250
| callback | Callback&lt;void&gt; | No| Callback for the event.|
E
ester.zhou 已提交
251 252 253

**Example**

E
esterzhou 已提交
254 255 256 257 258 259 260 261 262 263
```ts
try {
    config.off('enabledAccessibilityExtensionListChange', () => {
        console.info('Unsubscribe enabled accessibility extension list change state success');
    });
} catch (exception) {
    console.error('failed to Unsubscribe enabled accessibility extension list change state, because ' +
    JSON.stringify(exception));
};
```
E
ester.zhou 已提交
264 265 266 267 268 269 270 271 272

## Config

Implements configuration, acquisition, and listening for attributes.

### set

set(value: T): Promise&lt;void&gt;;

E
esterzhou 已提交
273
Sets the attribute value. This API uses a promise to return the result.
E
ester.zhou 已提交
274 275 276 277 278 279 280 281 282 283 284 285 286

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Attribute value to set.|

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
287
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
288 289 290

**Example**

E
esterzhou 已提交
291 292 293 294 295 296 297 298 299 300 301 302
```ts
let value = true;
try {
    config.highContrastText.set(value).then(() => {
        console.info('set highContrastText succeed');
    }).catch((err) => {
        console.error('failed to set highContrastText, because ' + JSON.stringify(err));
    });
} catch (exception) {
    console.error('failed to set config, because ' + JSON.stringify(exception));
};
```
E
ester.zhou 已提交
303 304 305 306 307

### set

set(value: T, callback: AsyncCallback&lt;void&gt;): void;

E
esterzhou 已提交
308
Sets the attribute value. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
309 310 311 312 313 314 315 316

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | T | Yes| Attribute value to set.|
E
esterzhou 已提交
317
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result.|
E
ester.zhou 已提交
318 319 320

**Example**

E
esterzhou 已提交
321 322 323 324 325 326 327 328 329 330 331 332 333 334
```ts
let value = true;
try {
    config.highContrastText.set(value, (err, data) => {
        if (err) {
            console.error('failed to set highContrastText, because ' + JSON.stringify(err));
            return;
        }
        console.info('set highContrastText succeed');
    });
} catch (exception) {
    console.error('failed to set config, because ' + JSON.stringify(exception));
};
```
E
ester.zhou 已提交
335 336 337 338 339

### get

get(): Promise&lt;T&gt;;

E
esterzhou 已提交
340
Obtains the attribute value. This API uses a promise to return the result.
E
ester.zhou 已提交
341 342 343 344 345 346 347

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
348
| Promise&lt;T&gt; | Promise used to return the value obtained.|
E
ester.zhou 已提交
349 350 351

**Example**

E
esterzhou 已提交
352 353 354 355 356 357 358 359 360
```ts
let value;
config.highContrastText.get().then((data) => {
    value = data;
    console.info('get highContrastText success');
}).catch((err) => {
    console.error('failed to get highContrastText, because ' + JSON.stringify(err));
});
```
E
ester.zhou 已提交
361 362 363 364 365

### get

get(callback: AsyncCallback&lt;T&gt;): void;

E
esterzhou 已提交
366
Obtains the attribute value. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
367 368 369 370 371 372 373

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
374
| callback | AsyncCallback&lt;T&gt; | Yes| Callback used to return the attribute value.|
E
ester.zhou 已提交
375 376 377

**Example**

E
esterzhou 已提交
378 379 380 381 382 383 384 385 386 387 388
```ts
let value;
config.highContrastText.get((err, data) => {
    if (err) {
        console.error('failed to get highContrastText, because ' + JSON.stringify(err));
        return;
    }
    value = data;
    console.info('get highContrastText success');
});
```
E
ester.zhou 已提交
389 390 391 392 393

### on

on(callback: Callback&lt;T&gt;): void;

E
esterzhou 已提交
394
Adds a listener for attribute changes. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
395 396 397 398 399 400 401 402 403 404 405

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | Callback&lt;T&gt; | Yes| Callback invoked when the attribute changes.|

**Example**

E
esterzhou 已提交
406 407 408 409 410 411 412 413 414
```ts
try {
    config.highContrastText.on((data) => {
        console.info('subscribe highContrastText success, result: ' + JSON.stringify(data));
    });
} catch (exception) {
    console.error('failed subscribe highContrastText, because ' + JSON.stringify(exception));
}
```
E
ester.zhou 已提交
415 416 417 418 419

### off

off(callback?: Callback&lt;T&gt;): void;

E
esterzhou 已提交
420
Cancels the listener for attribute changes. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
421 422 423 424 425 426 427

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
428
| callback | Callback&lt;T&gt; | No| Callback for the event.|
E
ester.zhou 已提交
429 430 431

**Example**

E
esterzhou 已提交
432 433 434 435 436
```ts
config.highContrastText.off((data) => {
    console.info('Unsubscribe highContrastText success, result: ' + JSON.stringify(data));
});
```
E
ester.zhou 已提交
437 438 439 440 441 442 443 444 445 446 447 448 449

## DaltonizationColorFilter

Enumerates the daltonization filters.

**System capability**: SystemCapability.BarrierFree.Accessibility.Core

| Name| Description|
| -------- | -------- |
| Normal | Filter for normal users.|
| Protanomaly | Filter for protanomaly.|
| Deuteranomaly | Filter for deuteranomaly.|
| Tritanomaly  | Filter for tritanomaly.|