harmony 鸿蒙@ohos.accessibility.config (System Accessibility Configuration)

  • 2022-10-28
  • 浏览 (679)

@ohos.accessibility.config (System Accessibility Configuration)

The System Accessibility Configuration module allows you to configure system accessibility features, including accessibility extension, high-contrast text, mouse buttons, and captions.

NOTE

  • 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.

Modules to Import

import config from '@ohos.accessibility.config';

Attributes

System capability: SystemCapability.BarrierFree.Accessibility.Core

Name Type Readable Writable Description
highContrastText Config<boolean> Yes Yes Whether to enable high-contrast text.
invertColor Config<boolean> Yes Yes Whether to enable color inversion.
daltonizationColorFilter Config&lt;DaltonizationColorFilter&gt; Yes Yes Configuration of the daltonization filter.
contentTimeout Config<number> Yes Yes Recommended duration for content display. The value ranges from 0 to 5000, in milliseconds.
animationOff Config<boolean> Yes Yes Whether to disable animation.
brightnessDiscount Config<number> Yes Yes Brightness discount. The value ranges from 0 to 1.0.
mouseKey Config<boolean> Yes Yes Whether to enable the mouse button feature.
mouseAutoClick Config<number> Yes Yes Interval for automatic mouse clicks. The value ranges from 0 to 5000, in milliseconds.
shortkey Config<boolean> Yes Yes Whether to enable the accessibility extension shortcut key.
shortkeyTarget Config<string> Yes Yes Target application for the accessibility extension shortcut key. The value format is ‘bundleName/abilityName’.
captions Config<boolean> Yes Yes Whether to enable captions.
captionsStyle Config<accessibility.CaptionsStyle> Yes Yes Captions style.
audioMono10+ Config<boolean> Yes Yes Whether to enable mono audio. The value True means to enable mono audio, and False means the opposite.
audioBalance10+ Config<number> Yes Yes Audio balance for the left and right audio channels. The value ranges from -1.0 to 1.0.

enableAbility

enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;): Promise&lt;void&gt;;

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
name string Yes Name of the accessibility extension ability. The format is ‘bundleName/abilityName’.
capability Array&lt;accessibility.Capability&gt; Yes Capability of the accessibility extension ability.

Return value

Type Description
Promise&lt;void&gt; Promise that returns no value.

Error codes

For details about the error codes, see Accessibility Error Codes.

ID Error Message
9300001 Invalid bundle name or ability name.
9300002 Target ability already enabled.

Example

import accessibility from '@ohos.accessibility';
import config from '@ohos.accessibility.config';

let name: string = 'com.ohos.example/axExtension';
let capability : accessibility.Capability[] = ['retrieve'];
try {
    config.enableAbility(name, capability).then(() => {
      console.info('enable ability succeed');
    }).catch((err: object) => {
      console.error('failed to enable ability, because ' + JSON.stringify(err));
    });
} catch (exception) {
    console.error('failed to enable ability, because ' + JSON.stringify(exception));
};

enableAbility

enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, callback: AsyncCallback&lt;void&gt;): void;

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
name string Yes Name of the accessibility extension ability. The format is ‘bundleName/abilityName’.
capability Array&lt;accessibility.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.

ID Error Message
9300001 Invalid bundle name or ability name.
9300002 Target ability already enabled.

Example

import accessibility from '@ohos.accessibility';
import config from '@ohos.accessibility.config';
import { BusinessError } from '@ohos.base';

let name: string = 'com.ohos.example/axExtension';
let capability: accessibility.Capability[] = ['retrieve'];
try {
    config.enableAbility(name, capability, (err: BusinessError<void>) => {
        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));
};

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
name string Yes Name of the accessibility extension ability. The format is ‘bundleName/abilityName’.

Return value

Type Description
Promise&lt;void&gt; Promise that returns no value.

Error codes

For details about the error codes, see Accessibility Error Codes.

ID Error Message
9300001 Invalid bundle name or ability name.

Example

import accessibility from '@ohos.accessibility';
import config from '@ohos.accessibility.config';

let name: string = 'com.ohos.example/axExtension';
try {
    config.disableAbility(name).then(() => {
      console.info('disable ability succeed');
    }).catch((err: object) => {
      console.error('failed to disable ability, because ' + JSON.stringify(err));
    });
} catch (exception) {
    console.error('failed to disable ability, because ' + JSON.stringify(exception));
};

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
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.

ID Error Message
9300001 Invalid bundle name or ability name.

Example

import accessibility from '@ohos.accessibility';
import config from '@ohos.accessibility.config';
import { BusinessError } from '@ohos.base';

let name: string = 'com.ohos.example/axExtension';
try {
    config.disableAbility(name, (err: BusinessError<void>) => {
        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));
};

on(‘enabledAccessibilityExtensionListChange’)

on(type: ‘enabledAccessibilityExtensionListChange’, callback: Callback&lt;void&gt;): void;

Adds a listener for changes in the list of enabled accessibility extension abilities. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

Name Type Mandatory Description
type string Yes Listening type. The value is fixed at ‘enabledAccessibilityExtensionListChange’, indicating listening for changes in the list of enabled accessibility extension abilities.
callback Callback&lt;void&gt; Yes Callback invoked when the list of enabled accessibility extension abilities changes.

Example

import config from '@ohos.accessibility.config';

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));
};

off(‘enabledAccessibilityExtensionListChange’)

off(type: ‘enabledAccessibilityExtensionListChange’, callback?: Callback&lt;void&gt;): void;

Cancels the listener for changes in the list of enabled accessibility extension abilities. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

Name Type Mandatory Description
type string Yes Listening type. The value is fixed at ‘enabledAccessibilityExtensionListChange’, indicating listening for changes in the list of enabled accessibility extension abilities.
callback Callback&lt;void&gt; No Callback for the event. The value must be the same as the value of callback in on(‘enabledAccessibilityExtensionListChange’). If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.

Example

import config from '@ohos.accessibility.config';

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));
};

Config

Implements configuration, acquisition, and listening for attributes.

set

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

Sets the attribute value. This API uses a promise to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

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

Return value

Type Description
Promise&lt;void&gt; Promise that returns no value.

Example

import config from '@ohos.accessibility.config';

let value: boolean = true;
try {
    config.highContrastText.set(value).then(() => {
        console.info('set highContrastText succeed');
    }).catch((err: object) => {
        console.error('failed to set highContrastText, because ' + JSON.stringify(err));
    });
} catch (exception) {
    console.error('failed to set config, because ' + JSON.stringify(exception));
};

set

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

Sets the attribute value. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

Name Type Mandatory Description
value T Yes Attribute value to set.
callback AsyncCallback&lt;void&gt; Yes Callback used to return the result.

Example

import config from '@ohos.accessibility.config';
import { BusinessError } from '@ohos.base';

let value: boolean = true;
try {
    config.highContrastText.set(value, (err: BusinessError<void>) => {
        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));
};

get

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

Obtains the attribute value. This API uses a promise to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Return value

Type Description
Promise&lt;T&gt; Promise used to return the value obtained.

Example

import config from '@ohos.accessibility.config';
import { BusinessError } from '@ohos.base';

let value: boolean;
config.highContrastText.get().then((data: boolean) => {
    value = data;
    console.info('get highContrastText success');
}).catch((err: object) => {
    console.error('failed to get highContrastText, because ' + JSON.stringify(err));
});

get

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

Obtains the attribute value. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

Name Type Mandatory Description
callback AsyncCallback&lt;T&gt; Yes Callback used to return the attribute value.

Example

import config from '@ohos.accessibility.config';
import { BusinessError } from '@ohos.base';

let value: boolean;
config.highContrastText.get((err: BusinessError<void>, data: boolean) => {
    if (err) {
        console.error('failed to get highContrastText, because ' + JSON.stringify(err));
        return;
    }
    value = data;
    console.info('get highContrastText success');
});

on

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

Adds a listener for attribute changes. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

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

Example

import config from '@ohos.accessibility.config';

try {
    config.highContrastText.on((data: boolean) => {
        console.info('subscribe highContrastText success, result: ' + JSON.stringify(data));
    });
} catch (exception) {
    console.error('failed subscribe highContrastText, because ' + JSON.stringify(exception));
}

off

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

Cancels the listener for attribute changes. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.BarrierFree.Accessibility.Core

Parameters

Name Type Mandatory Description
callback Callback&lt;T&gt; No Callback for the event. The value must be the same as the value of callback in on(). If this parameter is not specified, listening will be disabled for all callbacks corresponding to the specified type.

Example

import config from '@ohos.accessibility.config';

config.highContrastText.off((data: boolean) => {
    console.info('Unsubscribe highContrastText success, result: ' + JSON.stringify(data));
});

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.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞