提交 e98b9d60 编写于 作者: Z zaki

Modify the accessible subsystem document and add the description of the api error code

Signed-off-by: Nzaki <zhoujun141@huawei.com>
Change-Id: I5b687b801855bbf51cea600847e116179706889a
上级 934b06ac
...@@ -11,7 +11,7 @@ GesturePath表示手势路径信息。 ...@@ -11,7 +11,7 @@ GesturePath表示手势路径信息。
## 导入模块 ## 导入模块
```ts ```ts
import GesturePath from "@ohos.accessibility.GesturePath"; import GesturePath from '@ohos.accessibility.GesturePath';
``` ```
## GesturePath ## GesturePath
...@@ -43,7 +43,7 @@ constructor(durationTime: number); ...@@ -43,7 +43,7 @@ constructor(durationTime: number);
**示例:** **示例:**
```typescript ```ts
let durationTime = 20; let durationTime = 20;
let gesturePath = new GesturePath(durationTime); let gesturePath = new GesturePath(durationTime);
``` ```
...@@ -11,7 +11,7 @@ GesturePoint表示手势触摸点。 ...@@ -11,7 +11,7 @@ GesturePoint表示手势触摸点。
## 导入模块 ## 导入模块
```ts ```ts
import GesturePoint from "@ohos.accessibility.GesturePoint"; import GesturePoint from '@ohos.accessibility.GesturePoint';
``` ```
## GesturePoint ## GesturePoint
...@@ -44,7 +44,7 @@ constructor(positionX: number, positionY: number); ...@@ -44,7 +44,7 @@ constructor(positionX: number, positionY: number);
**示例:** **示例:**
```typescript ```ts
let positionX = 1; let positionX = 1;
let positionY = 2; let positionY = 2;
let gesturePoint = new GesturePoint(positionX, positionY); let gesturePoint = new GesturePoint(positionX, positionY);
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
## 导入模块 ## 导入模块
```typescript ```ts
import config from "@ohos.accessibility.config"; import config from '@ohos.accessibility.config';
``` ```
## 属性 ## 属性
...@@ -27,171 +27,243 @@ import config from "@ohos.accessibility.config"; ...@@ -27,171 +27,243 @@ import config from "@ohos.accessibility.config";
| mouseKey | [Config](#config)\<boolean>| 是 | 是 | 表示鼠标键功能启用状态。 | | mouseKey | [Config](#config)\<boolean>| 是 | 是 | 表示鼠标键功能启用状态。 |
| mouseAutoClick | [Config](#config)\<number>| 是 | 是 | 表示鼠标自动点击功能启用状态。取值 0~5000,单位为毫秒。 | | mouseAutoClick | [Config](#config)\<number>| 是 | 是 | 表示鼠标自动点击功能启用状态。取值 0~5000,单位为毫秒。 |
| shortkey | [Config](#config)\<boolean>| 是 | 是 | 表示辅助扩展快捷键功能启用状态。 | | shortkey | [Config](#config)\<boolean>| 是 | 是 | 表示辅助扩展快捷键功能启用状态。 |
| shortkeyTarget | [Config](#config)\<string>| 是 | 是 | 表示辅助扩展快捷键的目标配置。取值为辅助应用的名称,格式为:"bundleName/abilityName"。 | | shortkeyTarget | [Config](#config)\<string>| 是 | 是 | 表示辅助扩展快捷键的目标配置。取值为辅助应用的名称,格式为:'bundleName/abilityName'。 |
| captions | [Config](#config)\<boolean>| 是 | 是 | 表示辅助字幕功能启用状态。 | | captions | [Config](#config)\<boolean>| 是 | 是 | 表示辅助字幕功能启用状态。 |
| captionsStyle | [Config](#config)\<[accessibility.CaptionsStyle](./js-apis-accessibility.md#captionsstyle8)>| 是 | 是 | 表示辅助字幕的配置。 | | captionsStyle | [Config](#config)\<[CaptionsStyle](js-apis-accessibility.md#captionsstyle8)>| 是 | 是 | 表示辅助字幕的配置。 |
## enableAbility ## enableAbility
enableAbility(name: string, capability: Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt;): Promise&lt;void&gt;; enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;): Promise&lt;void&gt;;
启用辅助扩展。 启用辅助扩展,使用Promise异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"。 | | name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'。 |
| capability | Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt;) | 是 | 辅助应用的能力属性。 | | capability | Array&lt;[accessibility.Capability](js-apis-accessibility.md#capability)&gt;) | 是 | 辅助应用的能力属性。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise实例,用于返回方法执行结果。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name. |
| 9300002 | Target ability already enabled. |
**示例:** **示例:**
```typescript ```ts
config.enableAbility("com.ohos.example/axExtension", ['retrieve']) let name = 'com.ohos.example/axExtension';
.then(() => { let capability = ['retrieve'];
console.info('enable succeed'); try {
}).catch((error) => { config.enableAbility(name, capability).then(() => {
console.error('enable failed'); 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));
};
``` ```
## enableAbility ## enableAbility
enableAbility(name: string, capability: Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt;, callback: AsyncCallback&lt;void&gt;): void; enableAbility(name: string, capability: Array&lt;accessibility.Capability&gt;, callback: AsyncCallback&lt;void&gt;): void;
启用辅助扩展。 启用辅助扩展,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"。 | | name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'。 |
| capability | Array&lt;[accessibility.Capability](./js-apis-accessibility.md#capability)&gt; | 是 | 辅助应用的能力属性。 | | capability | Array&lt;[accessibility.Capability](js-apis-accessibility.md#capability)&gt; | 是 | 辅助应用的能力属性。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回方法执行结果。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name. |
| 9300002 | Target ability already enabled. |
**示例:** **示例:**
```typescript ```ts
config.enableAbility("com.ohos.example/axExtension", ['retrieve'], (err, data) => { let name = 'com.ohos.example/axExtension';
let capability = ['retrieve'];
try {
config.enableAbility(name, capability, (err, data) => {
if (err) { if (err) {
console.error('enable failed'); console.error('failed to enable ability, because ' + JSON.stringify(err));
return; return;
} }
console.info('enable succeed'); console.info('enable ability succeed');
}) });
``` } catch (exception) {
console.error('failed to enable ability, because ' + JSON.stringify(exception));
};
```
## disableAbility ## disableAbility
disableAbility(name: string): Promise&lt;void&gt;; disableAbility(name: string): Promise&lt;void&gt;;
关闭辅助扩展。 关闭辅助扩展,使用Promise异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"。 | | name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise实例,用于返回方法执行结果。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name. |
**示例:** **示例:**
```typescript ```ts
config.disableAbility("com.ohos.example/axExtension") let name = 'com.ohos.example/axExtension';
.then(() => { try {
console.info('disable succeed'); config.enableAbility(name).then(() => {
}).catch((error) => { console.info('disable ability succeed');
console.error('disable failed'); }).catch((err) => {
console.error('failed to disable ability, because ' + JSON.stringify(err));
}); });
``` } catch (exception) {
console.error('failed to disable ability, because ' + JSON.stringify(exception));
};
```
## disableAbility ## disableAbility
disableAbility(name: string, callback: AsyncCallback&lt;void&gt;): void; disableAbility(name: string, callback: AsyncCallback&lt;void&gt;): void;
关闭辅助扩展。 关闭辅助扩展,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"。 | | name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回方法执行结果。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300001 | Invalid bundle name or ability name. |
**示例:** **示例:**
```typescript ```ts
config.disableAbility("com.ohos.example/axExtension", (err, data) => { let name = 'com.ohos.example/axExtension';
try {
config.disableAbility(name, (err, data) => {
if (err) { if (err) {
console.error('disable failed'); console.error('failed to enable ability, because ' + JSON.stringify(err));
return; return;
} }
console.info('disable succeed'); console.info('disable succeed');
}) });
``` } catch (exception) {
console.error('failed to enable ability, because ' + JSON.stringify(exception));
};
```
## on('enableAbilityListsStateChanged') ## on('enabledAccessibilityExtensionListChange')
on(type: 'enableAbilityListsStateChanged', callback: Callback&lt;void&gt;): void; on(type: 'enabledAccessibilityExtensionListChange', callback: Callback&lt;void&gt;): void;
添加启用的辅助扩展的列表变化监听。 添加启用的辅助扩展的列表变化监听,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 参数固定为enableAbilityListsStateChanged,监听启用的辅助扩展的列表变化。 | | type | string | 是 | 参数固定为enabledAccessibilityExtensionListChange,监听启用的辅助扩展的列表变化。 |
| callback | Callback&lt;void&gt; | 是 | 回调函数,在启用的辅助扩展的列表变化时通过此函数进行通知。 | | callback | Callback&lt;void&gt; | 是 | 回调函数,在启用的辅助扩展的列表变化时通过此函数进行通知。 |
**示例:** **示例:**
```typescript ```ts
config.on('enableAbilityListsStateChanged',() => { try {
console.info('ax extension ability enable list changed'); config.on('enabledAccessibilityExtensionListChange', () => {
console.info('subscribe enabled accessibility extension list change state success');
}).catch((err) => {
console.error('failed to subscribe enabled accessibility extension list change state, because ' +
JSON.stringify(err));
}); });
``` } catch (exception) {
console.error('failed to subscribe enabled accessibility extension list change state, because ' +
JSON.stringify(exception));
};
```
## off('enableAbilityListsStateChanged') ## off('enabledAccessibilityExtensionListChange')
off(type: 'enableAbilityListsStateChanged', callback?: Callback&lt;void&gt;): void; off(type: 'enabledAccessibilityExtensionListChange', callback?: Callback&lt;void&gt;): void;
取消启用的辅助扩展的列表变化监听。 取消启用的辅助扩展的列表变化监听,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 否 | 参数固定为enableAbilityListsStateChanged,监听启用的辅助扩展的列表变化。 | | type | string | 否 | 参数固定为enabledAccessibilityExtensionListChange,监听启用的辅助扩展的列表变化。 |
| callback | Callback&lt;void&gt; | 否 | 要取消的监听回调函数。 | | callback | Callback&lt;void&gt; | 否 | 要取消的监听回调函数。 |
**示例:** **示例:**
```typescript ```ts
config.off('enableAbilityListsStateChanged'); try {
``` config.off('enabledAccessibilityExtensionListChange', () => {
console.info('unSubscribe enabled accessibility extension list change state success');
}).catch((err) => {
console.error('failed to unSubscribe enabled accessibility extension list change state, because ' +
JSON.stringify(err));
});
} catch (exception) {
console.error('failed to unSubscribe enabled accessibility extension list change state, because ' +
JSON.stringify(exception));
};
```
## Config ## Config
...@@ -201,152 +273,178 @@ off(type: 'enableAbilityListsStateChanged', callback?: Callback&lt;void&gt;): vo ...@@ -201,152 +273,178 @@ off(type: 'enableAbilityListsStateChanged', callback?: Callback&lt;void&gt;): vo
set(value: T): Promise&lt;void&gt;; set(value: T): Promise&lt;void&gt;;
设置属性。 设置属性,使用Promise异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | T | 是 | 设置的属性值。 | | value | T | 是 | 设置的属性值。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise实例,用于返回方法执行结果。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:** **示例:**
```typescript ```ts
config.highContrastText.set(true) let value = true;
.then(() => { try {
console.info('highContrastText set succeed'); config.highContrastText.set(value).then(() => {
}).catch((error) => { console.info('set highContrastText succeed');
console.error('highContrastText set failed'); }).catch((err) => {
console.error('failed to set highContrastText, because ' + JSON.stringify(err));
}); });
``` } catch (exception) {
console.error('failed to set config, because ' + JSON.stringify(exception));
};
```
### set ### set
set(value: T, callback: AsyncCallback&lt;void&gt;): void; set(value: T, callback: AsyncCallback&lt;void&gt;): void;
设置属性。 设置属性,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| value | T | 是 | 设置的属性值。 | | value | T | 是 | 设置的属性值。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回方法执行结果。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数。 |
**示例:** **示例:**
```typescript ```ts
config.highContrastText.set(true, (err, data) => { let value = true;
try {
config.highContrastText.set(value, (err, data) => {
if (err) { if (err) {
console.error('highContrastText set failed'); console.error('failed to set highContrastText, because ' + JSON.stringify(err));
return; return;
} }
console.info('highContrastText set succeed'); console.info('set highContrastText succeed');
}) });
``` } catch (exception) {
console.error('failed to set config, because ' + JSON.stringify(exception));
};
```
### get ### get
get(): Promise&lt;T&gt;; get(): Promise&lt;T&gt;;
获取属性。 获取属性,使用Promise异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;T&gt; | Promise实例,用于返回属性值。 | | Promise&lt;T&gt; | Promise对象,返回对应属性值。 |
**示例:** **示例:**
```typescript ```ts
config.highContrastText.get() let value;
.then((value) => { config.highContrastText.get().then((data) => {
console.info('highContrastText get succeed'); value = data;
}).catch((error) => { console.info('get highContrastText success');
console.error('highContrastText get failed'); }).catch((err) => {
}); console.error('failed to get highContrastText, because ' + JSON.stringify(err));
``` });
```
### get ### get
get(callback: AsyncCallback&lt;T&gt;): void; get(callback: AsyncCallback&lt;T&gt;): void;
获取属性。 获取属性,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回属性值。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,返回属性值。 |
**示例:** **示例:**
```typescript ```ts
config.highContrastText.get((err, data) => { let value;
config.highContrastText.get((err, data) => {
if (err) { if (err) {
console.error('highContrastText get failed'); console.error('failed to get highContrastText, because ' + JSON.stringify(err));
return; return;
} }
console.info('highContrastText get succeed'); value = data;
}) console.info('get highContrastText success');
``` });
```
### on ### on
on(callback: Callback&lt;T&gt;): void; on(callback: Callback&lt;T&gt;): void;
添加属性变化监听。 添加属性变化监听,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | Callback&lt;T&gt; | 是 | 回调函数,在属性变化时通过此函数进行通知。 | | callback | Callback&lt;T&gt; | 是 | 回调函数,在属性变化时通过此函数进行通知。 |
**示例:** **示例:**
```typescript ```ts
config.highContrastText.on(() => { try {
console.info('highContrastText changed'); config.highContrastText.on((err, data) => {
if (err) {
console.error('failed subscribe highContrastText, because ' + JSON.stringify(err));
return;
}
console.info('subscribe highContrastText success');
}); });
``` } catch (exception) {
console.error('failed subscribe highContrastText, because ' + JSON.stringify(exception));
}
```
### off ### off
off(callback?: Callback&lt;T&gt;): void; off(callback?: Callback&lt;T&gt;): void;
取消属性变化监听。 取消属性变化监听,使用callback异步回调
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | Callback&lt;T&gt; | 否 | 要取消的监听回调函数。 | | callback | Callback&lt;T&gt; | 否 | 要取消的监听回调函数。 |
**示例:** **示例:**
```typescript ```ts
config.highContrastText.off(); config.highContrastText.off((err, data) => {
``` if (err) {
console.error('failed unSubscribe highContrastText, because ' + JSON.stringify(err));
return;
}
console.info('unSubscribe highContrastText success');
});
```
## DaltonizationColorFilter ## DaltonizationColorFilter
......
...@@ -11,14 +11,15 @@ AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境, ...@@ -11,14 +11,15 @@ AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境,
## 使用说明 ## 使用说明
在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取。 在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例
```js ```js
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility' import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility'
let axContext;
class MainAbility extends AccessibilityExtensionAbility { class MainAbility extends AccessibilityExtensionAbility {
onConnect(): void { onConnect(): void {
console.log('AxExtensionAbility onConnect'); console.log('AxExtensionAbility onConnect');
let axContext = this.context; axContext = this.context;
} }
} }
``` ```
...@@ -97,11 +98,15 @@ setTargetBundleName(targetNames: Array\<string>): Promise\<void>; ...@@ -97,11 +98,15 @@ setTargetBundleName(targetNames: Array\<string>): Promise\<void>;
```ts ```ts
let targetNames = ['com.ohos.xyz']; let targetNames = ['com.ohos.xyz'];
this.context.setTargetBundleName().then(() => { try {
axContext.setTargetBundleName(targetNames).then(() => {
console.info('set target bundle names success'); console.info('set target bundle names success');
}).catch((err) => { }).catch((err) => {
console.error('failed to set target bundle names because ' + JSON.stringify(err)); console.error('failed to set target bundle names, because ' + JSON.stringify(err));
}); });
} catch (exception) {
console.error('failed to set target bundle names, because ' + JSON.stringify(exception));
};
``` ```
## AccessibilityExtensionContext.setTargetBundleName ## AccessibilityExtensionContext.setTargetBundleName
...@@ -123,13 +128,17 @@ setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>) ...@@ -123,13 +128,17 @@ setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>)
```ts ```ts
let targetNames = ['com.ohos.xyz']; let targetNames = ['com.ohos.xyz'];
this.context.setTargetBundleName().then((err, data) => { try {
axContext.setTargetBundleName(targetNames, (err, data) => {
if (err) { if (err) {
console.error('failed to set target bundle names because ' + JSON.stringify(err)); console.error('failed to set target bundle names, because ' + JSON.stringify(err));
return; return;
} }
console.info('set target bundle names success'); console.info('set target bundle names success');
}); });
} catch (exception) {
console.error('failed to set target bundle names, because ' + JSON.stringify(exception));
};
``` ```
## AccessibilityExtensionContext.getFocusElement ## AccessibilityExtensionContext.getFocusElement
...@@ -152,16 +161,28 @@ getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>; ...@@ -152,16 +161,28 @@ getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>;
| ----------------------------------- | ---------------------- | | ----------------------------------- | ---------------------- |
| Promise&lt;AccessibilityElement&gt; | Promise对象,返回当前对应的焦点元素。 | | Promise&lt;AccessibilityElement&gt; | Promise对象,返回当前对应的焦点元素。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let focusElement; let focusElement;
this.context.getFocusElement().then((data) => { try {
axContext.getFocusElement().then((data) => {
focusElement = data; focusElement = data;
console.log('get focus element success'); console.log('get focus element success');
}).catch((err) => { }).catch((err) => {
console.error('failed to get focus element because ' + JSON.stringify(err)); console.error('failed to get focus element, because ' + JSON.stringify(err));
}); });
} catch (exception) {
console.error('failed to get focus element, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getFocusElement ## AccessibilityExtensionContext.getFocusElement
...@@ -178,18 +199,29 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void; ...@@ -178,18 +199,29 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是 | 回调函数,返回当前对应的焦点元素。 | | callback | AsyncCallback&lt;AccessibilityElement&gt; | 是 | 回调函数,返回当前对应的焦点元素。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let focusElement; try {
this.context.getFocusElement().then((err, data) => { axContext.getFocusElement((err, data) => {
if (err) { if (err) {
console.error('failed to get focus element because ' + JSON.stringify(err)); console.error('failed to get focus element, because ' + JSON.stringify(err));
return; return;
} }
focusElement = data; focusElement = data;
console.info('get focus element success'); console.info('get focus element success');
}); });
} catch (exception) {
console.error('failed to get focus element, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getFocusElement ## AccessibilityExtensionContext.getFocusElement
...@@ -210,15 +242,18 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib ...@@ -210,15 +242,18 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib
**示例:** **示例:**
```ts ```ts
let isAccessibilityFocus = true; try {
this.context.getFocusElement(isAccessibilityFocus).then((err, data) => { axContext.getFocusElement(isAccessibilityFocus, (err, data) => {
if (err) { if (err) {
console.error('failed to get focus element because ' + JSON.stringify(err)); console.error('failed to get focus element, because ' + JSON.stringify(err));
return; return;
} }
focusElement = data; focusElement = data;
console.info('get focus element success'); console.info('get focus element success');
}); });
} catch (exception) {
console.error('failed to get focus element, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getWindowRootElement ## AccessibilityExtensionContext.getWindowRootElement
...@@ -240,16 +275,28 @@ getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>; ...@@ -240,16 +275,28 @@ getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>;
| ----------------------------------- | ---------------------- | | ----------------------------------- | ---------------------- |
| Promise&lt;AccessibilityElement&gt; | Promise对象,返回指定屏幕的所有窗口。 | | Promise&lt;AccessibilityElement&gt; | Promise对象,返回指定屏幕的所有窗口。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let rootElement; let rootElement;
this.context.getWindowRootElement().then((data) => { try {
axContext.getWindowRootElement().then((data) => {
rootElement = data; rootElement = data;
console.log('get root element of the window success'); console.log('get root element of the window success');
}).catch((err) => { }).catch((err) => {
console.error('failed to get root element of the window because ' + JSON.stringify(err)); console.error('failed to get root element of the window, because ' + JSON.stringify(err));
}); });
} catch (exception) {
console.error('failed to get root element of the window, ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getWindowRootElement ## AccessibilityExtensionContext.getWindowRootElement
...@@ -266,18 +313,29 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void; ...@@ -266,18 +313,29 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是 | 回调函数,返回指定窗口的根节点元素。 | | callback | AsyncCallback&lt;AccessibilityElement&gt; | 是 | 回调函数,返回指定窗口的根节点元素。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let rootElement; try {
this.context.getWindowRootElement().then((err, data) => { axContext.getWindowRootElement((err, data) => {
if (err) { if (err) {
console.error('failed to get root element of the window because ' + JSON.stringify(err)); console.error('failed to get root element of the window, because ' + JSON.stringify(err));
return; return;
} }
rootElement = data; rootElement = data;
console.info('get root element of the window success'); console.info('get root element of the window success');
}); });
} catch (exception) {
console.error('failed to get root element of the window, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getWindowRootElement ## AccessibilityExtensionContext.getWindowRootElement
...@@ -295,19 +353,29 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle ...@@ -295,19 +353,29 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle
| windowId | number | 是 | 指定窗口的编号,未指定则从当前活跃窗口获取。 | | windowId | number | 是 | 指定窗口的编号,未指定则从当前活跃窗口获取。 |
| callback | AsyncCallback&lt;AccessibilityElement&gt; | 是 | 回调函数,返回指定窗口的根节点元素。 | | callback | AsyncCallback&lt;AccessibilityElement&gt; | 是 | 回调函数,返回指定窗口的根节点元素。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let displayId = 10; try {
let rootElement; axContext.getWindowRootElement(windowId, (err, data) => {
this.context.getWindowRootElement(displayId).then((err, data) => {
if (err) { if (err) {
console.error('failed to get root element of the window because ' + JSON.stringify(err)); console.error('failed to get root element of the window, because ' + JSON.stringify(err));
return; return;
} }
rootElement = data; rootElement = data;
console.info('get root element of the window success'); console.info('get root element of the window success');
}); });
} catch (exception) {
console.error('failed to get root element of the window, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getWindows ## AccessibilityExtensionContext.getWindows
...@@ -330,16 +398,28 @@ getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>; ...@@ -330,16 +398,28 @@ getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;
| ----------------------------------- | ---------------------- | | ----------------------------------- | ---------------------- |
| Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise对象,返回指定屏幕的所有窗口。 | | Promise&lt;Array&lt;AccessibilityElement&gt;&gt; | Promise对象,返回指定屏幕的所有窗口。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let windows; let windows;
this.context.getWindows().then((data) => { try {
axContext.getWindows().then((data) => {
windows = data; windows = data;
console.log('get windows success'); console.log('get windows success');
}).catch((err) => { }).catch((err) => {
console.error('failed to get windows because ' + JSON.stringify(err)); console.error('failed to get windows, because ' + JSON.stringify(err));
}); });
} catch (exception) {
console.error('failed to get windows, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getWindows ## AccessibilityExtensionContext.getWindows
...@@ -356,18 +436,30 @@ getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void; ...@@ -356,18 +436,30 @@ getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是 | 回调函数,返回指定屏幕的所有窗口。 | | callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是 | 回调函数,返回指定屏幕的所有窗口。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let windows; let windows;
this.context.getWindows().then((err, data) => { try {
axContext.getWindows((err, data) => {
if (err) { if (err) {
console.error('failed to get windows because ' + JSON.stringify(err)); console.error('failed to get windows, because ' + JSON.stringify(err));
return; return;
} }
windows = data; windows = data;
console.info('get windows success'); console.info('get windows success');
}); });
} catch (exception) {
console.error('failed to get windows, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.getWindows ## AccessibilityExtensionContext.getWindows
...@@ -385,19 +477,31 @@ getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityEleme ...@@ -385,19 +477,31 @@ getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityEleme
| displayId | number | 是 | 指定的屏幕编号,未指定则从默认主屏幕获取。 | | displayId | number | 是 | 指定的屏幕编号,未指定则从默认主屏幕获取。 |
| callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是 | 回调函数,返回指定屏幕的所有窗口。 | | callback | AsyncCallback&lt;Array&lt;AccessibilityElement&gt;&gt; | 是 | 回调函数,返回指定屏幕的所有窗口。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
let displayId = 10;
let windows; let windows;
this.context.getWindows(displayId).then((err, data) => { let displayId = 10;
try {
axContext.getWindows(displayId, (err, data) => {
if (err) { if (err) {
console.error('failed to get windows because ' + JSON.stringify(err)); console.error('failed to get windows, because ' + JSON.stringify(err));
return; return;
} }
windows = data; windows = data;
console.info('get windows success'); console.info('get windows success');
}); });
} catch (exception) {
console.error('failed to get windows, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.injectGesture ## AccessibilityExtensionContext.injectGesture
...@@ -420,20 +524,32 @@ injectGesture(gesturePath: GesturePath): Promise\<void>; ...@@ -420,20 +524,32 @@ injectGesture(gesturePath: GesturePath): Promise\<void>;
| ----------------------------------- | ---------------------- | | ----------------------------------- | ---------------------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 | | Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
import { GesturePath } from "../@ohos.accessibility.GesturePath"; import GesturePath from "@ohos.accessibility.GesturePath";
let gesturePath = new GesturePath(100); let gesturePath = new GesturePath(100);
for (let i = 0; i < 10; i++) { try {
let gesturePoint = new GesturePosition(100, i * 200); for (let i = 0; i < 10; i++) {
gesturePath.positions.push(gesturePoint); let gesturePoint = new GesturePoint(100, i * 200);
} gesturePath.points.push(gesturePoint);
this.context.gestureInject(gesturePath, () => { }
axContext.injectGesture(gesturePath).then(() => {
console.info('inject gesture success'); console.info('inject gesture success');
}).catch((err) => { }).catch((err) => {
console.error('failed to inject gesture because ' + JSON.stringify(err)); console.error('failed to inject gesture, because ' + JSON.stringify(err));
}); });
} catch (exception) {
console.error('failed to inject gesture, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityExtensionContext.injectGesture ## AccessibilityExtensionContext.injectGesture
...@@ -450,25 +566,38 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void ...@@ -450,25 +566,38 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
| gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是 | 表示手势的路径信息。 | | gesturePath | [GesturePath](js-apis-accessibility-GesturePath.md#gesturepath) | 是 | 表示手势的路径信息。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,表示注入手势执行结果的回调。 | | callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,表示注入手势执行结果的回调。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300003 | Do not have accessibility right for this operation. |
**示例:** **示例:**
```ts ```ts
import GesturePath from "@ohos.accessibility.GesturePath";
let gesturePath = new GesturePath(100); let gesturePath = new GesturePath(100);
for (let i = 0; i < 10; i++) { try {
let gesturePoint = new GesturePosition(100, i * 200); for (let i = 0; i < 10; i++) {
gesturePath.positions.push(gesturePoint); let gesturePoint = new GesturePoint(100, i * 200);
} gesturePath.points.push(gesturePoint);
this.context.gestureInject(gesturePath, (err, data) => { }
axContext.injectGesture(gesturePath, (err, data) => {
if (err) { if (err) {
console.error('failed to inject gesture because ' + JSON.stringify(err)); console.error('failed to inject gesture, because ' + JSON.stringify(err));
return; return;
} }
console.info('inject gesture success'); console.info('inject gesture success');
}); });
} catch (exception) {
console.error('failed to inject gesture, because ' + JSON.stringify(exception));
}
``` ```
## AccessibilityElement<sup>9</sup> ## AccessibilityElement<sup>9+</sup>
无障碍节点元素。 无障碍节点元素, 在调用AccessibilityElement的方法前,需要先通过[AccessibilityExtensionContext.getFocusElement()](#accessibilityextensioncontextgetfocuselement)或者[AccessibilityExtensionContext.getWindowRootElement()](#accessibilityextensioncontextgetwindowrootelement)获取AccessibilityElement实例
**系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Core
...@@ -489,18 +618,14 @@ attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>; ...@@ -489,18 +618,14 @@ attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let attributeNames; let attributeNames;
try { rootElement.attributeNames().then((data) => {
accessibilityElement.attributeNames().then((data) => {
console.log('get attribute names success'); console.log('get attribute names success');
attributeNames = data; attributeNames = data;
}).catch((err) => { }).catch((err) => {
console.log('get attribute names err: ' + JSON.stringify(err)); console.log('failed to get attribute names, because ' + JSON.stringify(err));
}); });
} catch (e) {
console.log('An unexpected error occurred. Error:' + e);
}
``` ```
## attributeNames ## attributeNames
...@@ -519,20 +644,16 @@ attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\ ...@@ -519,20 +644,16 @@ attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let attributeNames; let attributeNames;
try { rootElement.attributeNames((err, data) => {
accessibilityElement.attributeNames().then((err, data) => {
if (err) { if (err) {
console.error('failed to get attribute names because ' + JSON.stringify(err)); console.error('failed to get attribute names, because ' + JSON.stringify(err));
return; return;
} }
attributeNames = data; attributeNames = data;
console.info('get attribute names success'); console.info('get attribute names success');
}); });
} catch (e) {
console.log('An unexpected error occurred. Error:' + e);
}
``` ```
## AccessibilityElement.attributeValue ## AccessibilityElement.attributeValue
...@@ -554,21 +675,27 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi ...@@ -554,21 +675,27 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi
| ---------------------------------------- | ------------------------ | | ---------------------------------------- | ------------------------ |
| Promise&lt;ElementAttributeValues[T]&gt; | Promise对象,返回根据节点属性名称获取的属性值。 | | Promise&lt;ElementAttributeValues[T]&gt; | Promise对象,返回根据节点属性名称获取的属性值。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300004 | This property does not exist. |
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let attributeName = 'name';
let attributeValue;
try { try {
let attributeName = 'name'; rootElement.attributeValue(attributeName).then((data) => {
accessibilityElement.attributeValue(attributeName).then((data) => {
console.log('get attribute value by name success'); console.log('get attribute value by name success');
attribtueValue = data; attribtueValue = data;
}).catch((err) => { }).catch((err) => {
console.log('get attribute value by name err: ' + JSON.stringify(err)); console.log('failed to get attribute value, because ' + JSON.stringify(err));
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to get attribute value, because ' + JSON.stringify(exception));
} }
``` ```
## AccessibilityElement.attributeValue ## AccessibilityElement.attributeValue
...@@ -587,23 +714,31 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T, ...@@ -587,23 +714,31 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
| attributeName | T | 是 | 表示属性的名称。 | | attributeName | T | 是 | 表示属性的名称。 |
| callback | AsyncCallback&lt;ElementAttributeValues[T]&gt; | 是 | 回调函数,返回根据节点属性名称获取的属性值。 | | callback | AsyncCallback&lt;ElementAttributeValues[T]&gt; | 是 | 回调函数,返回根据节点属性名称获取的属性值。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300004 | This property does not exist. |
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let attributeValue; let attributeValue;
let attributeName = 'name';
try { try {
let attributeName = 'name'; rootElement.attributeValue(attributeName, (err, data) => {
accessibilityElement.attributeValue(attributeName).then((err, data) => {
if (err) { if (err) {
console.error('failed to get attribute value because ' + JSON.stringify(err)); console.error('failed to get attribute value, because ' + JSON.stringify(err));
return; return;
} }
attributeValue = data; attributeValue = data;
console.info('get attribute value success'); console.info('get attribute value success');
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to get attribute value, because ' + JSON.stringify(exception));
} }
``` ```
## actionNames ## actionNames
...@@ -623,18 +758,14 @@ actionNames(): Promise\<Array\<string>>; ...@@ -623,18 +758,14 @@ actionNames(): Promise\<Array\<string>>;
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let actionNames; let actionNames;
try { rootElement.actionNames().then((data) => {
accessibilityElement.actionNames().then((data) => {
console.log('get action names success'); console.log('get action names success');
actionNames = data; actionNames = data;
}).catch((err) => { }).catch((err) => {
console.log('get action names err: ' + JSON.stringify(err)); console.log('failed to get action names because ' + JSON.stringify(err));
}); });
} catch (e) {
console.log('An unexpected error occurred. Error:' + e);
}
``` ```
## actionNames ## actionNames
...@@ -653,20 +784,16 @@ actionNames(callback: AsyncCallback\<Array\<string>>): void; ...@@ -653,20 +784,16 @@ actionNames(callback: AsyncCallback\<Array\<string>>): void;
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let actionNames; let actionNames;
try { rootElement.actionNames((err, data) => {
accessibilityElement.actionNames().then((err, data) => {
if (err) { if (err) {
console.error('failed to get action names because ' + JSON.stringify(err)); console.error('failed to get action names, because ' + JSON.stringify(err));
return; return;
} }
actionNames = data; actionNames = data;
console.info('get action names success'); console.info('get action names success');
}); });
} catch (e) {
console.log('An unexpected error occurred. Error:' + e);
}
``` ```
## performAction ## performAction
...@@ -689,20 +816,28 @@ performAction(actionName: string, parameters?: object): Promise\<boolean>; ...@@ -689,20 +816,28 @@ performAction(actionName: string, parameters?: object): Promise\<boolean>;
| ---------------------------------------- | ------------------------ | | ---------------------------------------- | ------------------------ |
| Promise&lt;boolean&gt; | Promise对象,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 | | Promise&lt;boolean&gt; | Promise对象,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300005 | This action is not supported. |
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let performActionRes; let performActionRes;
try { try {
accessibilityElement.performAction('action').then((data) => { rootElement.performAction('action').then((data) => {
console.info('perform action success'); console.info('perform action success');
performActionRes = data; performActionRes = data;
}).catch((err) => { }).catch((err) => {
console.log('failed to perform action because ' + JSON.stringify(err)); console.log('failed to perform action, because ' + JSON.stringify(err));
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to perform action, because ' + JSON.stringify(exception));
} }
``` ```
## performAction ## performAction
...@@ -718,24 +853,32 @@ performAction(actionName: string, callback: AsyncCallback\<boolean>): void; ...@@ -718,24 +853,32 @@ performAction(actionName: string, callback: AsyncCallback\<boolean>): void;
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| ----------- | ---------------------------------------- | ---- | -------------- | | ----------- | ---------------------------------------- | ---- | -------------- |
| actionName | string | 是 | 表示属性的名称。 | | actionName | string | 是 | 表示属性的名称。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。|
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300005 | This action is not supported. |
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let performActionRes; let performActionRes;
try { try {
accessibilityElement.performAction('action').then((err, data) => { rootElement.performAction('action', (err, data) => {
if (err) { if (err) {
console.error('failed to perform action because ' + JSON.stringify(err)); console.error('failed to perform action, because ' + JSON.stringify(err));
return; return;
} }
performActionRes = data; performActionRes = data;
console.info('perform action success'); console.info('perform action success');
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to perform action, because ' + JSON.stringify(exception));
} }
``` ```
## performAction ## performAction
...@@ -752,35 +895,43 @@ performAction(actionName: string, parameters: object, callback: AsyncCallback\<b ...@@ -752,35 +895,43 @@ performAction(actionName: string, parameters: object, callback: AsyncCallback\<b
| ----------- | ---------------------------------------- | ---- | -------------- | | ----------- | ---------------------------------------- | ---- | -------------- |
| actionName | string | 是 | 表示属性的名称。 | | actionName | string | 是 | 表示属性的名称。 |
| parameters | object | 是 | 表示执行操作时所需要的参数。 | | parameters | object | 是 | 表示执行操作时所需要的参数。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。|
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../errorcodes/errorcode-accessibility.md)
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300005 | This action is not supported. |
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let actionName = 'action'; let actionName = 'action';
let parameters = { let parameters = {
'setText': 'test text' 'setText': 'test text'
}; };
let performActionRes; let performActionRes;
try { try {
accessibilityElement.performAction(actionName, parameters).then((err, data) => { rootElement.performAction(actionName, parameters, (err, data) => {
if (err) { if (err) {
console.error('failed to perform action because ' + JSON.stringify(err)); console.error('failed to perform action, because ' + JSON.stringify(err));
return; return;
} }
performActionRes = data; performActionRes = data;
console.info('perform action success'); console.info('perform action success');
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to perform action, because ' + JSON.stringify(exception));
} }
``` ```
## findElement('content') ## findElement('content')
findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>; findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityElement>>;
根据节点内容查询所有节点元素。 根据节点内容查询所有节点元素,使用Promise异步回调
**系统能力:** SystemCapability.BarrierFree.Accessibility.Core **系统能力:** SystemCapability.BarrierFree.Accessibility.Core
...@@ -800,19 +951,19 @@ findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityEl ...@@ -800,19 +951,19 @@ findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityEl
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let type = 'content'; let type = 'content';
let condition = 'keyword'; let condition = 'keyword';
let elements; let elements;
try { try {
accessibilityElement.findElement(type, condition).then((data) => { rootElement.findElement(type, condition).then((data) => {
elements = data; elements = data;
console.log('find element success'); console.log('find element success');
}).catch((err) => { }).catch((err) => {
console.log('failed to find element because ' + JSON.stringify(err)); console.log('failed to find element, because ' + JSON.stringify(err));
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to find element, because ' + JSON.stringify(exception));
} }
``` ```
## findElement('content') ## findElement('content')
...@@ -834,28 +985,28 @@ findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\< ...@@ -834,28 +985,28 @@ findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let type = 'content'; let type = 'content';
let condition = 'keyword'; let condition = 'keyword';
let elements; let elements;
try { try {
accessibilityElement.findElement(type, condition).then((err, data) => { rootElement.findElement(type, condition, (err, data) => {
if (err) { if (err) {
console.error('failed to find element because ' + JSON.stringify(err)); console.error('failed to find element, because ' + JSON.stringify(err));
return; return;
} }
elements = data; elements = data;
console.info('find element success'); console.info('find element success');
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to find element, because ' + JSON.stringify(exception));
} }
``` ```
## findElement('focusType') ## findElement('focusType')
findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>; findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElement>;
根据焦点元素类型查询节点元素。 根据焦点元素类型查询节点元素,使用Promise异步回调
**系统能力:** SystemCapability.BarrierFree.Accessibility.Core **系统能力:** SystemCapability.BarrierFree.Accessibility.Core
...@@ -875,26 +1026,26 @@ findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElem ...@@ -875,26 +1026,26 @@ findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElem
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let type = 'focusType'; let type = 'focusType';
let condition = 'normal'; let condition = 'normal';
let elements; let element;
try { try {
accessibilityElement.findElement(type, condition).then((data) => { rootElement.findElement(type, condition).then((data) => {
elements = data; element = data;
console.log('find element success'); console.log('find element success');
}).catch((err) => { }).catch((err) => {
console.log('failed to find element because ' + JSON.stringify(err)); console.log('failed to find element, because ' + JSON.stringify(err));
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to find element, because ' + JSON.stringify(exception));
} }
``` ```
## findElement('focusType') ## findElement('focusType')
findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void; findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<AccessibilityElement>): void;
根据焦点元素类型查询节点元素。 根据焦点元素类型查询节点元素,使用callback异步回调
**系统能力:** SystemCapability.BarrierFree.Accessibility.Core **系统能力:** SystemCapability.BarrierFree.Accessibility.Core
...@@ -909,28 +1060,28 @@ findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<Ac ...@@ -909,28 +1060,28 @@ findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<Ac
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let type = 'focusType'; let type = 'focusType';
let condition = 'normal'; let condition = 'normal';
let elements; let element;
try { try {
accessibilityElement.findElement(type, condition).then((err, data) => { rootElement.findElement(type, condition, (err, data) => {
if (err) { if (err) {
console.error('failed to find element because ' + JSON.stringify(err)); console.error('failed to find element, because ' + JSON.stringify(err));
return; return;
} }
elements = data; element = data;
console.info('find element success'); console.info('find element success');
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to find element, because ' + JSON.stringify(exception));
} }
``` ```
## findElement('focusDirection') ## findElement('focusDirection')
findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>; findElement(type: 'focusDirection', condition: FocusDirection): Promise\<AccessibilityElement>;
根据下一焦点元素方向查询节点元素。 根据下一焦点元素方向查询节点元素,使用Promise异步回调
**系统能力:** SystemCapability.BarrierFree.Accessibility.Core **系统能力:** SystemCapability.BarrierFree.Accessibility.Core
...@@ -950,26 +1101,26 @@ findElement(type: 'focusDirection', condition: FocusDirection): Promise\<Accessi ...@@ -950,26 +1101,26 @@ findElement(type: 'focusDirection', condition: FocusDirection): Promise\<Accessi
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let type = 'focusDirection'; let type = 'focusDirection';
let condition = 'up'; let condition = 'up';
let elements; let element;
try { try {
accessibilityElement.findElement(type, condition).then((data) => { rootElement.findElement(type, condition).then((data) => {
elements = data; element = data;
console.log('find element success'); console.log('find element success');
}).catch((err) => { }).catch((err) => {
console.log('failed to find element because ' + JSON.stringify(err)); console.log('failed to find element, because ' + JSON.stringify(err));
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to find element, because ' + JSON.stringify(exception));
} }
``` ```
## findElement('focusDirection') ## findElement('focusDirection')
findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void; findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCallback\<AccessibilityElement>): void;
根据下一焦点元素方向查询所有节点元素。 根据下一焦点元素方向查询所有节点元素,使用callback异步回调
**系统能力:** SystemCapability.BarrierFree.Accessibility.Core **系统能力:** SystemCapability.BarrierFree.Accessibility.Core
...@@ -984,20 +1135,20 @@ findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCa ...@@ -984,20 +1135,20 @@ findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCa
**示例:** **示例:**
```ts ```ts
let accessibilityElement; let rootElement;
let type = 'focusDirection'; let type = 'focusDirection';
let condition = 'up'; let condition = 'up';
let elements; let elements;
try { try {
accessibilityElement.findElement(type, condition).then((err, data) => { rootElement.findElement(type, condition, (err, data) => {
if (err) { if (err) {
console.error('failed to find element because ' + JSON.stringify(err)); console.error('failed to find element, because ' + JSON.stringify(err));
return; return;
} }
elements = data; elements = data;
console.info('find element success'); console.info('find element success');
}); });
} catch (e) { } catch (exception) {
console.log('An unexpected error occurred. Error:' + e); console.log('failed to find element, because ' + JSON.stringify(exception));
} }
``` ```
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## 导入模块 ## 导入模块
```typescript ```ts
import accessibility from '@ohos.accessibility'; import accessibility from '@ohos.accessibility';
``` ```
...@@ -144,7 +144,7 @@ import accessibility from '@ohos.accessibility'; ...@@ -144,7 +144,7 @@ import accessibility from '@ohos.accessibility';
## CaptionsManager<sup>8+</sup> ## CaptionsManager<sup>8+</sup>
字幕配置管理,在调用CaptionsManager的方法前,需要先通过 [accessibility.getCaptionsManager()](#accessibilitygetcaptionsmanager8)获取 captionsManager实例。 字幕配置管理,在调用CaptionsManager的方法前,需要先通过 [accessibility.getCaptionsManager()](#accessibilitygetcaptionsmanager8)获取 CaptionsManager实例。
**系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Hearing **系统能力**:以下各项对应的系统能力均为SystemCapability.BarrierFree.Accessibility.Hearing
...@@ -159,7 +159,7 @@ import accessibility from '@ohos.accessibility'; ...@@ -159,7 +159,7 @@ import accessibility from '@ohos.accessibility';
on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void; on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void;
监听字幕配置启用状态变化事件。 监听字幕配置启用状态变化事件,使用callback异步回调
**参数:** **参数:**
...@@ -170,18 +170,28 @@ on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void; ...@@ -170,18 +170,28 @@ on(type: 'enableChange', callback: Callback&lt;boolean&gt;): void;
**示例:** **示例:**
```typescript ```ts
let captionsManager = accessibility.getCaptionsManager(); let result = false;
captionsManager.on('enableChange',(data) => { let captionsManager = accessibility.getCaptionsManager();
console.info('success data:subscribeStateObserver : ' + JSON.stringify(data)) try {
captionsManager.on('enableChange', (err, data) => {
if (err) {
console.error('failed to subscribe caption manager enable state change, because ' + JSON.stringify(err));
return;
}
result = data;
console.info('subscribe caption manager enable state change success');
}); });
``` } catch (exception) {
console.error('failed to subscribe caption manager enable state change, because ' + JSON.stringify(exception));
}
```
### on('styleChange') ### on('styleChange')
on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void; on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void;
监听字幕风格变化事件。 监听字幕风格变化事件,使用callback异步回调
**参数:** **参数:**
...@@ -192,18 +202,28 @@ on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void; ...@@ -192,18 +202,28 @@ on(type: 'styleChange', callback: Callback&lt;CaptionsStyle&gt;): void;
**示例:** **示例:**
```typescript ```ts
let captionsManager = accessibility.getCaptionsManager(); let captionStyle;
captionsManager.on('styleChange',(data) => { let captionsManager = accessibility.getCaptionsManager();
console.info('success data:subscribeStateObserver : ' + JSON.stringify(data)) try {
captionsManager.on('styleChange', (err, data) => {
if (err) {
console.error('failed to subscribe caption manager style state change, because ' + JSON.stringify(err));
return;
}
captionStyle = data;
console.info('subscribe caption manager style state change success');
}); });
``` } catch (exception) {
console.error('failed to subscribe caption manager style state change, because ' + JSON.stringify(exception));
}
```
### off('enableChange') ### off('enableChange')
off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void; off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void;
取消监听字幕配置启用状态变化事件。 取消监听字幕配置启用状态变化事件,使用callback异步回调
**参数:** **参数:**
...@@ -214,18 +234,28 @@ off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void; ...@@ -214,18 +234,28 @@ off(type: 'enableChange', callback?: Callback&lt;boolean&gt;): void;
**示例:** **示例:**
```typescript ```ts
let captionsManager = accessibility.getCaptionsManager(); let result = false;
captionsManager.off('enableChange',(data) => { let captionsManager = accessibility.getCaptionsManager();
console.info('success data:unSubscribeStateObserver : ' + JSON.stringify(data)) try {
captionsManager.off('enableChange', (err, data) => {
if (err) {
console.error('failed to unSubscribe caption manager enable state change, because ' + JSON.stringify(err));
return;
}
result = data;
console.info('unSubscribe caption manager enable state change success');
}); });
``` } catch (exception) {
console.error('failed to unSubscribe caption manager enable state change, because ' + JSON.stringify(exception));
}
```
### off('styleChange') ### off('styleChange')
off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void; off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void;
取消字幕风格变化监听事件。 取消字幕风格变化监听事件,使用callback异步回调
**参数:** **参数:**
...@@ -236,12 +266,22 @@ off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void; ...@@ -236,12 +266,22 @@ off(type: 'styleChange', callback?: Callback&lt;CaptionsStyle&gt;): void;
**示例:** **示例:**
```typescript ```ts
let captionsManager = accessibility.getCaptionsManager(); let captionStyle;
captionsManager.off('styleChange',(data) => { let captionsManager = accessibility.getCaptionsManager();
console.info('success data:unSubscribeStateObserver : ' + JSON.stringify(data)) try {
captionsManager.off('styleChange', (err, data) => {
if (err) {
console.error('failed to unSubscribe caption manager style state change, because ' + JSON.stringify(err));
return;
}
captionStyle = data;
console.info('unSubscribe caption manager style state change success');
}); });
``` } catch (exception) {
console.error('failed to unSubscribe caption manager style state change, because ' + JSON.stringify(exception));
}
```
## EventInfo ## EventInfo
...@@ -284,11 +324,11 @@ constructor(jsonObject) ...@@ -284,11 +324,11 @@ constructor(jsonObject)
**示例:** **示例:**
```typescript ```ts
let eventInfo = new accessibility.EventInfo({ let eventInfo = new accessibility.EventInfo({
"type":"click", 'type':'click',
"bundleName":"com.example.MyApplication", 'bundleName':'com.example.MyApplication',
"triggerAction":"click" 'triggerAction':'click'
}); });
``` ```
...@@ -340,12 +380,17 @@ constructor(jsonObject) ...@@ -340,12 +380,17 @@ constructor(jsonObject)
| active | 窗口变为活动或不活动的窗口变化事件。 | | active | 窗口变为活动或不活动的窗口变化事件。 |
| focus | 窗口焦点发生变化的窗口变化事件。 | | focus | 窗口焦点发生变化的窗口变化事件。 |
## accessibility.getAbilityLists ## accessibility.getAbilityLists<sup>(deprecated)</sup>
getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt; getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;
查询辅助应用列表,使用Promise异步回调。 查询辅助应用列表,使用Promise异步回调。
> **说明:**
>
> 从API version 7开始支持,从API version 9开始废弃。
> 推荐使用[getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9)。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
...@@ -363,26 +408,39 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise&lt;A ...@@ -363,26 +408,39 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise&lt;A
**示例:** **示例:**
```typescript ```ts
accessibility.getAbilityLists("spoken", "enable").then((data) => { let abilityType = 'spoken';
console.info('success data:getAbilityList1 : ' + JSON.stringify(data)); let abilityState = 'enable';
let abilityList: accessibility.AccessibilityInfo[];
try {
accessibility.getAbilityLists(abilityType, abilityState).then((data) => {
for (let item of data) { for (let item of data) {
console.info(item.id); console.info(item.id);
console.info(item.name); console.info(item.name);
console.info(item.description); console.info(item.description);
console.info(item.bundleName); console.info(item.bundleName);
extensionList.push(item);
} }
}).catch((err) => { console.info('get accessibility extension list success');
console.error('failed to getAbilityList1 because ' + JSON.stringify(err)); }).catch((err) => {
}); console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
});
} catch (exception) {
console.error('failed to get accessibility extension list because ' + JSON.stringify(exception));
}
``` ```
## accessibility.getAbilityLists ## accessibility.getAbilityLists<sup>(deprecated)</sup>
getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;): void getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;): void
查询辅助应用列表,使用callback异步回调。 查询辅助应用列表,使用callback异步回调。
> **说明:**
>
> 从API version 7开始支持,从API version 9开始废弃。
> 推荐使用[getAccessibilityExtensionList()](#accessibilitygetaccessibilityextensionlist9-1)。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
...@@ -395,21 +453,120 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: Asyn ...@@ -395,21 +453,120 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: Asyn
**示例:** **示例:**
```typescript ```ts
accessibility.getAbilityLists("visual", "enable", (err, data) => { let abilityType = 'spoken';
let abilityState = 'enable';
let abilityList: accessibility.AccessibilityInfo[];
try {
accessibility.getAbilityLists(abilityType, abilityState, (err, data) => {
if (err) { if (err) {
console.error('failed to getAbilityList2 because ' + JSON.stringify(err)); console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
return; return;
} }
console.info('success data:getAbilityList2 : ' + JSON.stringify(data));
for (let item of data) { for (let item of data) {
console.info(item.id); console.info(item.id);
console.info(item.name); console.info(item.name);
console.info(item.description); console.info(item.description);
console.info(item.bundleName); console.info(item.bundleName);
abilityList.push(item);
} }
}); console.info('get accessibility extension list success');
``` }).catch((err) => {
console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
});
} catch (exception) {
console.error('failed to get accessibility extension list because ' + JSON.stringify(exception));
}
```
## accessibility.getAccessibilityExtensionList<sup>9+</sup>
getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState): Promise&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;
查询辅助应用列表,使用Promise异步回调。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| abilityType | [AbilityType](#abilitytype) | 是 | 辅助应用的类型。 |
| stateType | [AbilityState](#abilitystate) | 是 | 辅助应用的状态。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Array&lt;[AccessibilityAbilityInfo](#accessibilityabilityinfo)&gt;&gt; | Promise对象,返回辅助应用信息列表。 |
**示例:**
```ts
let abilityType = 'spoken';
let abilityState = 'enable';
let extensionList: accessibility.AccessibilityInfo[];
try {
accessibility.getAccessibilityExtensionList(abilityType, abilityState).then((data) => {
for (let item of data) {
console.info(item.id);
console.info(item.name);
console.info(item.description);
console.info(item.bundleName);
extensionList.push(item);
}
console.info('get accessibility extension list success');
}).catch((err) => {
console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
});
} catch (exception) {
console.error('failed to get accessibility extension list because ' + JSON.stringify(exception));
}
```
## accessibility.getAccessibilityExtensionList<sup>9+</sup>
getAccessibilityExtensionList(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback&lt;Array&lt;AccessibilityAbilityInfo&gt;&gt;): void
查询辅助应用列表,使用callback异步回调。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| abilityType | [AbilityType](#abilitytype) | 是 | 辅助应用的类型。 |
| stateType | [AbilityState](#abilitystate) | 是 | 辅助应用的状态。 |
| callback | AsyncCallback&lt;Array&lt;[AccessibilityAbilityInfo](#accessibilityabilityinfo)&gt;&gt; | 是 | 回调函数,返回辅助应用信息列表。 |
**示例:**
```ts
let abilityType = 'spoken';
let abilityState = 'enable';
let extensionList: accessibility.AccessibilityInfo[];
try {
accessibility.getAccessibilityExtensionList(abilityType, abilityState, (err, data) => {
if (err) {
console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
return;
}
for (let item of data) {
console.info(item.id);
console.info(item.name);
console.info(item.description);
console.info(item.bundleName);
extensionList.push(item);
}
console.info('get accessibility extension list success');
}).catch((err) => {
console.error('failed to get accessibility extension list because ' + JSON.stringify(err));
});
} catch (exception) {
console.error('failed to get accessibility extension list because ' + JSON.stringify(exception));
}
```
## accessibility.getCaptionsManager<sup>8+</sup> ## accessibility.getCaptionsManager<sup>8+</sup>
...@@ -427,7 +584,7 @@ getCaptionsManager(): CaptionsManager ...@@ -427,7 +584,7 @@ getCaptionsManager(): CaptionsManager
**示例:** **示例:**
```typescript ```ts
let captionsManager = accessibility.getCaptionsManager(); let captionsManager = accessibility.getCaptionsManager();
``` ```
...@@ -435,7 +592,7 @@ let captionsManager = accessibility.getCaptionsManager(); ...@@ -435,7 +592,7 @@ let captionsManager = accessibility.getCaptionsManager();
on(type: 'accessibilityStateChange', callback: Callback&lt;boolean&gt;): void on(type: 'accessibilityStateChange', callback: Callback&lt;boolean&gt;): void
监听辅助应用启用状态变化事件。 监听辅助应用启用状态变化事件,使用callback异步回调
**系统能力**:以下各项对应的系统能力有所不同,详见下表。 **系统能力**:以下各项对应的系统能力有所不同,详见下表。
...@@ -448,17 +605,25 @@ on(type: 'accessibilityStateChange', callback: Callback&lt;boolean&gt;): void ...@@ -448,17 +605,25 @@ on(type: 'accessibilityStateChange', callback: Callback&lt;boolean&gt;): void
**示例:** **示例:**
```typescript ```ts
accessibility.on('accessibilityStateChange',(data) => { try {
console.info('success data:subscribeStateObserver : ' + JSON.stringify(data)) accessibility.on('accessibilityStateChange', (err, data) => {
}); if (err) {
console.error('failed to subscribe accessibility state change, because ' + JSON.stringify(err));
return;
}
console.info('subscribe accessibility state change success');
});
} catch (exception) {
console.error('failed to subscribe accessibility state change, because ' + JSON.stringify(exception));
}
``` ```
## accessibility.on('touchGuideStateChange') ## accessibility.on('touchGuideStateChange')
on(type: 'touchGuideStateChange', callback: Callback&lt;boolean&gt;): void on(type: 'touchGuideStateChange', callback: Callback&lt;boolean&gt;): void
监听触摸浏览功能启用状态变化事件。 监听触摸浏览功能启用状态变化事件,使用callback异步回调
**系统能力**:以下各项对应的系统能力有所不同,详见下表。 **系统能力**:以下各项对应的系统能力有所不同,详见下表。
...@@ -471,17 +636,25 @@ on(type: 'touchGuideStateChange', callback: Callback&lt;boolean&gt;): void ...@@ -471,17 +636,25 @@ on(type: 'touchGuideStateChange', callback: Callback&lt;boolean&gt;): void
**示例:** **示例:**
```typescript ```ts
accessibility.on('touchGuideStateChange',(data) => { try {
console.info('success data:subscribeStateObserver : ' + JSON.stringify(data)) accessibility.on('touchGuideStateChange', (err, data) => {
}); if (err) {
console.error('failed to subscribe touch guide state change, because ' + JSON.stringify(err));
return;
}
console.info('subscribe touch guide state change success');
});
} catch (exception) {
console.error('failed to subscribe touch guide state change, because ' + JSON.stringify(exception));
}
``` ```
## accessibility.off('accessibilityStateChange') ## accessibility.off('accessibilityStateChange')
off(type: 'accessibilityStateChange', callback?: Callback&lt;boolean&gt;): void off(type: 'accessibilityStateChange', callback?: Callback&lt;boolean&gt;): void
取消监听辅助应用启用状态变化事件。 取消监听辅助应用启用状态变化事件,使用callback异步回调
**系统能力**:以下各项对应的系统能力有所不同,详见下表。 **系统能力**:以下各项对应的系统能力有所不同,详见下表。
...@@ -494,17 +667,25 @@ off(type: 'accessibilityStateChange', callback?: Callback&lt;boolean&gt;): void ...@@ -494,17 +667,25 @@ off(type: 'accessibilityStateChange', callback?: Callback&lt;boolean&gt;): void
**示例:** **示例:**
```typescript ```ts
accessibility.off('accessibilityStateChange',(data) => { try {
console.info('success data:unSubscribeStateObserver : ' + JSON.stringify(data)) accessibility.on('accessibilityStateChange', (err, data) => {
}); if (err) {
console.error('failed to unSubscribe accessibility state change, because ' + JSON.stringify(err));
return;
}
console.info('unSubscribe accessibility state change success');
});
} catch (exception) {
console.error('failed to unSubscribe accessibility state change, because ' + JSON.stringify(exception));
}
``` ```
## accessibility.off('touchGuideStateChange') ## accessibility.off('touchGuideStateChange')
off(type: 'touchGuideStateChange', callback?: Callback&lt;boolean&gt;): void off(type: 'touchGuideStateChange', callback?: Callback&lt;boolean&gt;): void
取消监听触摸浏览启用状态变化事件。 取消监听触摸浏览启用状态变化事件,使用callback异步回调
**系统能力**:以下各项对应的系统能力有所不同,详见下表。 **系统能力**:以下各项对应的系统能力有所不同,详见下表。
...@@ -517,10 +698,18 @@ off(type: 'touchGuideStateChange', callback?: Callback&lt;boolean&gt;): void ...@@ -517,10 +698,18 @@ off(type: 'touchGuideStateChange', callback?: Callback&lt;boolean&gt;): void
**示例:** **示例:**
```typescript ```ts
accessibility.off('touchGuideStateChange',(data) => { try {
console.info('success data:unSubscribeStateObserver : ' + JSON.stringify(data)) accessibility.on('touchGuideStateChange', (err, data) => {
}); if (err) {
console.error('failed to unSubscribe touch guide state change, because ' + JSON.stringify(err));
return;
}
console.info('unSubscribe touch guide state change success');
});
} catch (exception) {
console.error('failed to unSubscribe touch guide state change, because ' + JSON.stringify(exception));
}
``` ```
## accessibility.isOpenAccessibility ## accessibility.isOpenAccessibility
...@@ -539,7 +728,7 @@ isOpenAccessibility(): Promise&lt;boolean&gt; ...@@ -539,7 +728,7 @@ isOpenAccessibility(): Promise&lt;boolean&gt;
**示例:** **示例:**
```typescript ```ts
accessibility.isOpenAccessibility().then((data) => { accessibility.isOpenAccessibility().then((data) => {
console.info('success data:isOpenAccessibility : ' + JSON.stringify(data)) console.info('success data:isOpenAccessibility : ' + JSON.stringify(data))
}).catch((err) => { }).catch((err) => {
...@@ -563,7 +752,7 @@ isOpenAccessibility(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -563,7 +752,7 @@ isOpenAccessibility(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```typescript ```ts
accessibility.isOpenAccessibility((err, data) => { accessibility.isOpenAccessibility((err, data) => {
if (err) { if (err) {
console.error('failed to isOpenAccessibility because ' + JSON.stringify(err)); console.error('failed to isOpenAccessibility because ' + JSON.stringify(err));
...@@ -589,7 +778,7 @@ isOpenTouchGuide(): Promise&lt;boolean&gt; ...@@ -589,7 +778,7 @@ isOpenTouchGuide(): Promise&lt;boolean&gt;
**示例:** **示例:**
```typescript ```ts
accessibility.isOpenTouchGuide().then((data) => { accessibility.isOpenTouchGuide().then((data) => {
console.info('success data:isOpenTouchGuide : ' + JSON.stringify(data)) console.info('success data:isOpenTouchGuide : ' + JSON.stringify(data))
}).catch((err) => { }).catch((err) => {
...@@ -613,7 +802,7 @@ isOpenTouchGuide(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -613,7 +802,7 @@ isOpenTouchGuide(callback: AsyncCallback&lt;boolean&gt;): void
**示例:** **示例:**
```typescript ```ts
accessibility.isOpenTouchGuide((err, data) => { accessibility.isOpenTouchGuide((err, data) => {
if (err) { if (err) {
console.error('failed to isOpenTouchGuide because ' + JSON.stringify(err)); console.error('failed to isOpenTouchGuide because ' + JSON.stringify(err));
...@@ -623,12 +812,17 @@ accessibility.isOpenTouchGuide((err, data) => { ...@@ -623,12 +812,17 @@ accessibility.isOpenTouchGuide((err, data) => {
}); });
``` ```
## accessibility.sendEvent ## accessibility.sendEvent<sup>(deprecated)</sup>
sendEvent(event: EventInfo): Promise&lt;void&gt; sendEvent(event: EventInfo): Promise&lt;void&gt;
发送无障碍事件, 使用Promise异步回调。 发送无障碍事件, 使用Promise异步回调。
> **说明:**
>
> 从API version 7开始支持,从API version 9开始废弃。
> 推荐使用[sendAccessibilityEvent()](#accessibilitysendaccessibilityevent9)。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
...@@ -645,11 +839,11 @@ sendEvent(event: EventInfo): Promise&lt;void&gt; ...@@ -645,11 +839,11 @@ sendEvent(event: EventInfo): Promise&lt;void&gt;
**示例:** **示例:**
```typescript ```ts
let eventInfo = new accessibility.EventInfo({ let eventInfo = new accessibility.EventInfo({
"type":"click", 'type':'click',
"bundleName":"com.example.MyApplication", 'bundleName':'com.example.MyApplication',
"triggerAction":"click" 'triggerAction':'click'
}); });
accessibility.sendEvent(eventInfo).then(() => { accessibility.sendEvent(eventInfo).then(() => {
console.info('send event success'); console.info('send event success');
...@@ -658,12 +852,17 @@ accessibility.sendEvent(eventInfo).then(() => { ...@@ -658,12 +852,17 @@ accessibility.sendEvent(eventInfo).then(() => {
}); });
``` ```
## accessibility.sendEvent ## accessibility.sendEvent<sup>(deprecated)</sup>
sendEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void sendEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void
发送无障碍事件, 使用callback异步回调。 发送无障碍事件, 使用callback异步回调。
> **说明:**
>
> 从API version 7开始支持,从API version 9开始废弃。
> 推荐使用[sendAccessibilityEvent()](#accessibilitysendaccessibilityevent9-1)。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core **系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:** **参数:**
...@@ -675,11 +874,11 @@ sendEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void ...@@ -675,11 +874,11 @@ sendEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```typescript ```ts
let eventInfo = new accessibility.EventInfo({ let eventInfo = new accessibility.EventInfo({
"type":"click", 'type':'click',
"bundleName":"com.example.MyApplication", 'bundleName':'com.example.MyApplication',
"triggerAction":"click" 'triggerAction':'click'
}); });
accessibility.sendEvent(eventInfo, (err, data) => { accessibility.sendEvent(eventInfo, (err, data) => {
if (err) { if (err) {
...@@ -688,4 +887,79 @@ accessibility.sendEvent(eventInfo, (err, data) => { ...@@ -688,4 +887,79 @@ accessibility.sendEvent(eventInfo, (err, data) => {
} }
console.info('sendEvent success'); console.info('sendEvent success');
}); });
``` ```
## accessibility.sendAccessibilityEvent<sup>9+</sup>
sendAccessibilityEvent(event: EventInfo): Promise&lt;void&gt;
发送无障碍事件, 使用Promise异步回调。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| event | [EventInfo](#eventinfo) | 是 | 无障碍事件对象。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 无返回结果的Promise对象。 |
**示例:**
```ts
let eventInfo = new accessibility.EventInfo({
'type':'click',
'bundleName':'com.example.MyApplication',
'triggerAction':'click'
});
try {
accessibility.sendAccessibilityEvent(eventInfo).then(() => {
console.info('send event success');
}).catch((err) => {
console.error('failed to send event because ' + JSON.stringify(err));
});
} catch (exception) {
console.error('failed to send event because ' + JSON.stringify(exception));
}
```
## accessibility.sendAccessibilityEvent<sup>9+</sup>
sendAccessibilityEvent(event: EventInfo, callback: AsyncCallback&lt;void&gt;): void
发送无障碍事件, 使用callback异步回调。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| event | [EventInfo](#eventinfo) | 是 | 辅助事件对象。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 回调函数,如果发送无障碍事件失败,则 AsyncCallback中err有数据返回。 |
**示例:**
```ts
let eventInfo = new accessibility.EventInfo({
'type':'click',
'bundleName':'com.example.MyApplication',
'triggerAction':'click'
});
try {
accessibility.sendEvent(eventInfo, (err, data) => {
if (err) {
console.error('failed to send event because ' + JSON.stringify(err));
return;
}
console.info('send event success');
});
} catch (exception) {
console.error('failed to send event because ' + JSON.stringify(exception));
}
```
...@@ -94,8 +94,10 @@ onConnect(): void; ...@@ -94,8 +94,10 @@ onConnect(): void;
**示例:** **示例:**
```ts ```ts
onConnect(): void { class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
console.log("AxExtensionAbility onConnect"); onConnect() {
console.log('AxExtensionAbility onConnect');
}
}; };
``` ```
...@@ -110,8 +112,10 @@ onDisconnect(): void; ...@@ -110,8 +112,10 @@ onDisconnect(): void;
**示例:** **示例:**
```ts ```ts
onDisconnect(): void { class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
console.log("AxExtensionAbility onDisconnect"); onDisconnect() {
console.log('AxExtensionAbility onDisconnect');
}
}; };
``` ```
...@@ -127,15 +131,17 @@ onAccessibilityEvent(event: AccessibilityEvent): void; ...@@ -127,15 +131,17 @@ onAccessibilityEvent(event: AccessibilityEvent): void;
| 参数名 | 参数类型 | 必填 | 说明 | | 参数名 | 参数类型 | 必填 | 说明 |
| ----- | ---------------------------------------- | ---- | --------------- | | ----- | ---------------------------------------- | ---- | --------------- |
| event | [AccessibilityEvent](accessibilityevent) | 是 | 无障碍事件回调函数。无返回值。 | | event | [AccessibilityEvent](#accessibilityevent) | 是 | 无障碍事件回调函数。无返回值。 |
**示例:** **示例:**
```ts ```ts
onAccessibilityEvent(event: AccessibilityEvent): void { class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
console.log("AxExtensionAbility onAccessibilityEvent"); onAccessibilityEvent(event) {
console.log('AxExtensionAbility onAccessibilityEvent');
if (event.eventType == 'click') { if (event.eventType == 'click') {
console.log("AxExtensionAbility onAccessibilityEvent: click"); console.log('AxExtensionAbility onAccessibilityEvent: click');
}
} }
}; };
``` ```
...@@ -157,12 +163,14 @@ onKeyEvent(keyEvent: KeyEvent): boolean; ...@@ -157,12 +163,14 @@ onKeyEvent(keyEvent: KeyEvent): boolean;
**示例:** **示例:**
```ts ```ts
onKeyEvent(keyEvent: inputEventClient.KeyEvent): boolean { class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
console.log("AxExtensionAbility onKeyEvent"); onKeyEvent(keyEvent) {
console.log('AxExtensionAbility onKeyEvent');
if (keyEvent.keyCode == 22) { if (keyEvent.keyCode == 22) {
console.log("AxExtensionAbility onKeyEvent: intercept 22"); console.log('AxExtensionAbility onKeyEvent: intercept 22');
return true; return true;
} }
return false; return false;
}
}; };
``` ```
# 无障碍子系统错误码
## 9300001 输入无效的包名称或者Ability名称
**错误信息**
Invalid bundle name or ability name.
**错误描述**
当输入的包名称或者Ability名称无效时,方法将返回该错误码。
**可能原因**
该错误码表示输入无效的包名称或者Ability名称,可能原因如下:
1. 包名称不存在。
2. 包里面没有对应的Ability。
**处理步骤**
1. 检查包名称是否正确。
2. 检查包名对应的Ability是否正确。
## 9300002 目标Ability已启用
**错误信息**
Target ability already enabled.
**错误描述**
当目标Ability已启用时,方法将返回该错误码。
**可能原因**
该错误码表示目标Ability已启用,可能原因是目标Ability已经启用,无法再次启用。
**处理步骤**
1. 停止该目标Ability。
2. 重新启用该目标Ability。
## 9300003 不具备执行该操作的无障碍权限
**错误信息**
Do not have accessibility right for this operation.
**错误描述**
当应用执行了用户在启用无障碍扩展应用时没有开启的辅助操作时,方法将返回该错误码。
**可能原因**
该错误码表示应用不具备该操作的无障碍权限,可能原因是应用执行了用户在启用无障碍扩展应用时没有开启的辅助操作。
**处理步骤**
1. 尝试向用户提示请求执行无障碍辅助操作的必要性,并获取用户授权。
2. 重新启用无障碍扩展应用,并开启所需的辅助操作。
## 9300004 属性不存在
**错误信息**
This property does not exist.
**错误描述**
当输入无障碍节点元素中不存在的属性时,方法将返回该错误码。
**可能原因**
该错误码表示输入了无效的无障碍节点元素的属性,可能原因是无障碍节点元素中不存在该属性。
**处理步骤**
检查无障碍节点元素中是否存在该属性。
## 9300005 不支持该操作
**错误信息**
This action is not supported.
**错误描述**
当应用执行无障碍节点元素不支持的操作时,方法将返回该错误码。
**可能原因**
该错误码表示执行了无障碍节点元素不支持的操作,可能原因是无障碍节点元素不支持执行该操作。
**处理步骤**
确认该无障碍节点元素支持的操作列表中是否包含该操作。
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册