Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
b7b16f35
D
Docs
项目概览
OpenHarmony
/
Docs
接近 2 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b7b16f35
编写于
10月 19, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 19, 2022
浏览文件
操作
浏览文件
下载
差异文件
!10778 修改无障碍子系统文档,增加api错误码说明
Merge pull request !10778 from zaki/master
上级
c66f998d
e98b9d60
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
1110 addition
and
483 deletion
+1110
-483
zh-cn/application-dev/reference/apis/js-apis-accessibility-GesturePath.md
...n-dev/reference/apis/js-apis-accessibility-GesturePath.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-accessibility-GesturePoint.md
...-dev/reference/apis/js-apis-accessibility-GesturePoint.md
+2
-2
zh-cn/application-dev/reference/apis/js-apis-accessibility-config.md
...cation-dev/reference/apis/js-apis-accessibility-config.md
+255
-157
zh-cn/application-dev/reference/apis/js-apis-accessibility-extension-context.md
...reference/apis/js-apis-accessibility-extension-context.md
+359
-208
zh-cn/application-dev/reference/apis/js-apis-accessibility.md
...n/application-dev/reference/apis/js-apis-accessibility.md
+373
-99
zh-cn/application-dev/reference/apis/js-apis-application-AccessibilityExtensionAbility.md
...apis/js-apis-application-AccessibilityExtensionAbility.md
+23
-15
zh-cn/application-dev/reference/errorcodes/errorcode-accessibility.md
...ation-dev/reference/errorcodes/errorcode-accessibility.md
+96
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-accessibility-GesturePath.md
浏览文件 @
b7b16f35
...
@@ -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);
**示例:**
**示例:**
```
t
ypescript
```
t
s
let
durationTime
=
20
;
let
durationTime
=
20
;
let
gesturePath
=
new
GesturePath
(
durationTime
);
let
gesturePath
=
new
GesturePath
(
durationTime
);
```
```
zh-cn/application-dev/reference/apis/js-apis-accessibility-GesturePoint.md
浏览文件 @
b7b16f35
...
@@ -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);
**示例:**
**示例:**
```
t
ypescript
```
t
s
let
positionX
=
1
;
let
positionX
=
1
;
let
positionY
=
2
;
let
positionY
=
2
;
let
gesturePoint
=
new
GesturePoint
(
positionX
,
positionY
);
let
gesturePoint
=
new
GesturePoint
(
positionX
,
positionY
);
...
...
zh-cn/application-dev/reference/apis/js-apis-accessibility-config.md
浏览文件 @
b7b16f35
...
@@ -8,8 +8,8 @@
...
@@ -8,8 +8,8 @@
## 导入模块
## 导入模块
```
t
ypescript
```
t
s
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
<
[accessibility.Capability](./js-apis-accessibility.md#capability)
>
): Promise
<
void
>
;
enableAbility(name: string, capability: Array
<
accessibility.Capability
>
): Promise
<
void
>
;
启用辅助扩展。
启用辅助扩展
,使用Promise异步回调
。
**系统能力**
:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**
:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"
。 |
| name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'
。 |
| capability | Array
<
[accessibility.Capability](./
js-apis-accessibility.md#capability)
>
) | 是 | 辅助应用的能力属性。 |
| capability | Array
<
[accessibility.Capability](
js-apis-accessibility.md#capability)
>
) | 是 | 辅助应用的能力属性。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| Promise实例,用于返回方法执行结果。 |
| Promise
<
void
>
| 无返回结果的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
<
[accessibility.Capability](./js-apis-accessibility.md#capability)
>
, callback: AsyncCallback
<
void
>
): void;
enableAbility(name: string, capability: Array<
accessibility.Capability
>, callback: AsyncCallback<void>): void;
启用辅助扩展。
启用辅助扩展
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"。 |
| name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'。 |
| capability | Array
<
[accessibility.Capability](./js-apis-accessibility.md#capability)
>
| 是 | 辅助应用的能力属性。 |
| capability | Array<[accessibility.Capability](js-apis-accessibility.md#capability)> | 是 | 辅助应用的能力属性。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回方法执行结果。 |
| callback | AsyncCallback<void> | 是 | 回调函数。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../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';
if
(
err
)
{
let capability = ['retrieve'];
console
.
error
(
'
enable failed
'
);
try {
return
;
config.enableAbility(name, capability, (err, data) => {
}
if (err) {
console
.
info
(
'
enable succeed
'
);
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
disableAbility(name: string): Promise<void>;
disableAbility(name: string): Promise<void>;
关闭辅助扩展。
关闭辅助扩展
,使用Promise异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"
。 |
| name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'
。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| Promise实例,用于返回方法执行结果。 |
| Promise<void> | 无返回结果的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<void>): void;
disableAbility(name: string, callback: AsyncCallback<void>): void;
关闭辅助扩展。
关闭辅助扩展
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| name | string | 是 | 辅助应用的名称,格式为:"bundleName/abilityName"。 |
| name | string | 是 | 辅助应用的名称,格式为:'bundleName/abilityName'。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回方法执行结果。 |
| callback | AsyncCallback<void> | 是 | 回调函数。 |
**错误码:**
以下错误码的详细介绍请参见[无障碍子系统错误码](../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';
if
(
err
)
{
try {
console
.
error
(
'
disable failed
'
);
config.disableAbility(name, (err, data) => {
return
;
if (err) {
}
console.error('failed to enable ability, because ' + JSON.stringify(err));
console
.
info
(
'
disable succeed
'
);
return;
})
}
```
console.info('disable succeed');
});
} catch (exception) {
console.error('failed to enable ability, because ' + JSON.stringify(exception));
};
```
## on('enable
AbilityListsStateChanged
')
## on('enable
dAccessibilityExtensionListChange
')
on(type: 'enable
AbilityListsStateChanged
', callback: Callback
<
void
>
): void;
on(type: 'enable
dAccessibilityExtensionListChange
', callback: Callback<void>): void;
添加启用的辅助扩展的列表变化监听。
添加启用的辅助扩展的列表变化监听
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 参数固定为enableAbilityListsStateChanged
,监听启用的辅助扩展的列表变化。 |
| type | string | 是 | 参数固定为enabledAccessibilityExtensionListChange
,监听启用的辅助扩展的列表变化。 |
| callback | Callback
<
void
>
| 是 | 回调函数,在启用的辅助扩展的列表变化时通过此函数进行通知。 |
| callback | Callback<void> | 是 | 回调函数,在启用的辅助扩展的列表变化时通过此函数进行通知。 |
**示例:**
**示例:**
```
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('enable
AbilityListsStateChanged
')
## off('enable
dAccessibilityExtensionListChange
')
off(type: 'enable
AbilityListsStateChanged
', callback?: Callback
<
void
>
): void;
off(type: 'enable
dAccessibilityExtensionListChange
', callback?: Callback<void>): void;
取消启用的辅助扩展的列表变化监听。
取消启用的辅助扩展的列表变化监听
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| type | string | 否 | 参数固定为enableAbilityListsStateChanged
,监听启用的辅助扩展的列表变化。 |
| type | string | 否 | 参数固定为enabledAccessibilityExtensionListChange
,监听启用的辅助扩展的列表变化。 |
| callback | Callback
<
void
>
| 否 | 要取消的监听回调函数。 |
| callback | Callback<void> | 否 | 要取消的监听回调函数。 |
**示例:**
**示例:**
```
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<void>): vo
...
@@ -201,152 +273,178 @@ off(type: 'enableAbilityListsStateChanged', callback?: Callback<void>): vo
set(value: T): Promise<void>;
set(value: T): Promise<void>;
设置属性。
设置属性
,使用Promise异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| value | T | 是 | 设置的属性值。 |
| value | T | 是 | 设置的属性值。 |
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
| Promise
<
void
>
| Promise实例,用于返回方法执行结果
。 |
| Promise<void> | 无返回结果的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<void>): void;
set(value: T, callback: AsyncCallback<void>): void;
设置属性。
设置属性
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| value | T | 是 | 设置的属性值。 |
| value | T | 是 | 设置的属性值。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回方法执行结果
。 |
| callback | AsyncCallback<void> | 是 | 回调函数
。 |
**示例:**
**示例:**
```
typescript
```
ts
config
.
highContrastText
.
set
(
true
,
(
err
,
data
)
=>
{
let value = true;
if
(
err
)
{
try {
console
.
error
(
'
highContrastText set failed
'
);
config.highContrastText.set(value, (err, data) => {
return
;
if (err) {
}
console.error('failed to set highContrastText, because ' + JSON.stringify(err));
console
.
info
(
'
highContrastText set succeed
'
);
return;
})
}
```
console.info('set highContrastText succeed');
});
} catch (exception) {
console.error('failed to set config, because ' + JSON.stringify(exception));
};
```
### get
### get
get(): Promise<T>;
get(): Promise<T>;
获取属性。
获取属性
,使用Promise异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**返回值:**
**返回值:**
| 类型 | 说明 |
| 类型 | 说明 |
| -------- | -------- |
| -------- | -------- |
| Promise
<
T
>
| Promise实例,用于返回
属性值。 |
| Promise<T> | 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<T>): void;
get(callback: AsyncCallback<T>): void;
获取属性。
获取属性
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,返回属性值。 |
| callback | AsyncCallback<void> | 是 | 回调函数,返回属性值。 |
**示例:**
**示例:**
```
typescript
```
ts
config
.
highContrastText
.
get
((
err
,
data
)
=>
{
let value;
if
(
err
)
{
config.highContrastText.get((err, data) => {
console
.
error
(
'
highContrastText get failed
'
);
if (err) {
return
;
console.error('failed to get highContrastText, because ' + JSON.stringify(err));
}
return;
console
.
info
(
'
highContrastText get succeed
'
);
}
})
value = data;
```
console.info('get highContrastText success');
});
```
### on
### on
on(callback: Callback<T>): void;
on(callback: Callback<T>): void;
添加属性变化监听。
添加属性变化监听
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | Callback
<
T
>
| 是 | 回调函数,在属性变化时通过此函数进行通知。 |
| callback | Callback<T> | 是 | 回调函数,在属性变化时通过此函数进行通知。 |
**示例:**
**示例:**
```
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<T>): void;
off(callback?: Callback<T>): void;
取消属性变化监听。
取消属性变化监听
,使用callback异步回调
。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| callback | Callback
<
T
>
| 否 | 要取消的监听回调函数。 |
| callback | Callback<T> | 否 | 要取消的监听回调函数。 |
**示例:**
**示例:**
```
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
...
...
zh-cn/application-dev/reference/apis/js-apis-accessibility-extension-context.md
浏览文件 @
b7b16f35
...
@@ -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
{
console
.
info
(
'
set target bundle names success
'
);
axContext
.
setTargetBundleName
(
targetNames
).
then
(()
=>
{
}).
catch
((
err
)
=>
{
console
.
info
(
'
set target bundle names success
'
);
console
.
error
(
'
failed to set target bundle names because
'
+
JSON
.
stringify
(
err
));
}).
catch
((
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
{
if
(
err
)
{
axContext
.
setTargetBundleName
(
targetNames
,
(
err
,
data
)
=>
{
console
.
error
(
'
failed to set target bundle names because
'
+
JSON
.
stringify
(
err
));
if
(
err
)
{
return
;
console
.
error
(
'
failed to set target bundle names, because
'
+
JSON
.
stringify
(
err
));
}
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
<
AccessibilityElement
>
| Promise对象,返回当前对应的焦点元素。 |
| Promise
<
AccessibilityElement
>
| 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
{
focusElement
=
data
;
axContext
.
getFocusElement
().
then
((
data
)
=>
{
console
.
log
(
'
get focus element success
'
);
focusElement
=
data
;
}).
catch
((
err
)
=>
{
console
.
log
(
'
get focus element success
'
);
console
.
error
(
'
failed to get focus element because
'
+
JSON
.
stringify
(
err
));
}).
catch
((
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
<
AccessibilityElement
>
| 是 | 回调函数,返回当前对应的焦点元素。 |
| callback | AsyncCallback
<
AccessibilityElement
>
| 是 | 回调函数,返回当前对应的焦点元素。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../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
<
AccessibilityElement
>
| Promise对象,返回指定屏幕的所有窗口。 |
| Promise
<
AccessibilityElement
>
| 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
{
rootElement
=
data
;
axContext
.
getWindowRootElement
().
then
((
data
)
=>
{
console
.
log
(
'
get root element of the window success
'
);
rootElement
=
data
;
}).
catch
((
err
)
=>
{
console
.
log
(
'
get root element of the window success
'
);
console
.
error
(
'
failed to get root element of the window because
'
+
JSON
.
stringify
(
err
));
}).
catch
((
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
<
AccessibilityElement
>
| 是 | 回调函数,返回指定窗口的根节点元素。 |
| callback | AsyncCallback
<
AccessibilityElement
>
| 是 | 回调函数,返回指定窗口的根节点元素。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../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
<
AccessibilityElement
>
| 是 | 回调函数,返回指定窗口的根节点元素。 |
| callback | AsyncCallback
<
AccessibilityElement
>
| 是 | 回调函数,返回指定窗口的根节点元素。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../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
<
Array
<
AccessibilityElement
>>
| Promise对象,返回指定屏幕的所有窗口。 |
| Promise
<
Array
<
AccessibilityElement
>>
| 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
{
windows
=
data
;
axContext
.
getWindows
().
then
((
data
)
=>
{
console
.
log
(
'
get windows success
'
);
windows
=
data
;
}).
catch
((
err
)
=>
{
console
.
log
(
'
get windows success
'
);
console
.
error
(
'
failed to get windows because
'
+
JSON
.
stringify
(
err
));
}).
catch
((
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
<
Array
<
AccessibilityElement
>>
| 是 | 回调函数,返回指定屏幕的所有窗口。 |
| callback | AsyncCallback
<
Array
<
AccessibilityElement
>>
| 是 | 回调函数,返回指定屏幕的所有窗口。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../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
{
if
(
err
)
{
axContext
.
getWindows
((
err
,
data
)
=>
{
console
.
error
(
'
failed to get windows because
'
+
JSON
.
stringify
(
err
));
if
(
err
)
{
return
;
console
.
error
(
'
failed to get windows, because
'
+
JSON
.
stringify
(
err
));
}
return
;
windows
=
data
;
}
console
.
info
(
'
get windows success
'
);
windows
=
data
;
});
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
<
Array
<
AccessibilityElement
>>
| 是 | 回调函数,返回指定屏幕的所有窗口。 |
| callback | AsyncCallback
<
Array
<
AccessibilityElement
>>
| 是 | 回调函数,返回指定屏幕的所有窗口。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../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
;
if
(
err
)
{
try
{
console
.
error
(
'
failed to get windows because
'
+
JSON
.
stringify
(
err
));
axContext
.
getWindows
(
displayId
,
(
err
,
data
)
=>
{
return
;
if
(
err
)
{
}
console
.
error
(
'
failed to get windows, because
'
+
JSON
.
stringify
(
err
));
windows
=
data
;
return
;
console
.
info
(
'
get windows success
'
);
}
});
windows
=
data
;
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
<
void
>
| 无返回结果的Promise对象。 |
| Promise
<
void
>
| 无返回结果的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
);
}
axContext
.
injectGesture
(
gesturePath
).
then
(()
=>
{
console
.
info
(
'
inject gesture success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
failed to inject gesture, because
'
+
JSON
.
stringify
(
err
));
});
}
catch
(
exception
)
{
console
.
error
(
'
failed to inject gesture, because
'
+
JSON
.
stringify
(
exception
));
}
}
this
.
context
.
gestureInject
(
gesturePath
,
()
=>
{
console
.
info
(
'
inject gesture success
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
'
failed to inject gesture because
'
+
JSON
.
stringify
(
err
));
});
```
```
## 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
<
void
>
| 是 | 回调函数,表示注入手势执行结果的回调。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,表示注入手势执行结果的回调。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../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
)
=>
{
if
(
err
)
{
console
.
error
(
'
failed to inject gesture because
'
+
JSON
.
stringify
(
err
));
return
;
}
}
console
.
info
(
'
inject gesture success
'
);
axContext
.
injectGesture
(
gesturePath
,
(
err
,
data
)
=>
{
});
if
(
err
)
{
console
.
error
(
'
failed to inject gesture, because
'
+
JSON
.
stringify
(
err
));
return
;
}
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
accessibility
Element
;
let
root
Element
;
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
(
'
failed to get attribute names, because
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
get attribute names err:
'
+
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
accessibility
Element
;
let
root
Element
;
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
<
ElementAttributeValues[T]
>
| Promise对象,返回根据节点属性名称获取的属性值。 |
| Promise
<
ElementAttributeValues[T]
>
| 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
(
e
xception
)
{
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
<
ElementAttributeValues[T]
>
| 是 | 回调函数,返回根据节点属性名称获取的属性值。 |
| callback | AsyncCallback
<
ElementAttributeValues[T]
>
| 是 | 回调函数,返回根据节点属性名称获取的属性值。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../errorcodes/errorcode-accessibility.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300004 | This property does not exist. |
**示例:**
**示例:**
```
ts
```
ts
let
accessibility
Element
;
let
root
Element
;
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
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
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
(
'
failed to get action names because
'
+
JSON
.
stringify
(
err
));
console
.
log
(
'
get action names err:
'
+
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
accessibility
Element
;
let
root
Element
;
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
<
boolean
>
| Promise对象,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 |
| Promise
<
boolean
>
| Promise对象,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 |
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../errorcodes/errorcode-accessibility.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300005 | This action is not supported. |
**示例:**
**示例:**
```
ts
```
ts
let
accessibility
Element
;
let
root
Element
;
let
performActionRes
;
let
performActionRes
;
try
{
try
{
accessibility
Element
.
performAction
(
'
action
'
).
then
((
data
)
=>
{
root
Element
.
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
(
e
xception
)
{
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
<
boolean
>
| 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。|
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../errorcodes/errorcode-accessibility.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300005 | This action is not supported. |
**示例:**
**示例:**
```
ts
```
ts
let
accessibility
Element
;
let
root
Element
;
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
(
e
xception
)
{
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
<
boolean
>
| 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。 |
| callback | AsyncCallback
<
boolean
>
| 是 | 回调函数,返回执行指定操作后的回调结果,true为执行成功,false为执行失败。|
**错误码:**
以下错误码的详细介绍请参见
[
无障碍子系统错误码
](
../errorcodes/errorcode-accessibility.md
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------- |
| 9300005 | This action is not supported. |
**示例:**
**示例:**
```
ts
```
ts
let
accessibility
Element
;
let
root
Element
;
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
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
let
type
=
'
content
'
;
let
type
=
'
content
'
;
let
condition
=
'
keyword
'
;
let
condition
=
'
keyword
'
;
let
elements
;
let
elements
;
try
{
try
{
accessibility
Element
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
root
Element
.
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
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
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
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
let
type
=
'
focusType
'
;
let
type
=
'
focusType
'
;
let
condition
=
'
normal
'
;
let
condition
=
'
normal
'
;
let
element
s
;
let
element
;
try
{
try
{
accessibility
Element
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
root
Element
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
element
s
=
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
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
let
type
=
'
focusType
'
;
let
type
=
'
focusType
'
;
let
condition
=
'
normal
'
;
let
condition
=
'
normal
'
;
let
element
s
;
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
;
}
}
element
s
=
data
;
element
=
data
;
console
.
info
(
'
find element success
'
);
console
.
info
(
'
find element success
'
);
});
});
}
catch
(
e
)
{
}
catch
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
let
type
=
'
focusDirection
'
;
let
type
=
'
focusDirection
'
;
let
condition
=
'
up
'
;
let
condition
=
'
up
'
;
let
element
s
;
let
element
;
try
{
try
{
accessibility
Element
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
root
Element
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
element
s
=
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
(
e
xception
)
{
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
accessibility
Element
;
let
root
Element
;
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
(
e
xception
)
{
console
.
log
(
'
An unexpected error occurred. Error:
'
+
e
);
console
.
log
(
'
failed to find element, because
'
+
JSON
.
stringify
(
exception
)
);
}
}
```
```
zh-cn/application-dev/reference/apis/js-apis-accessibility.md
浏览文件 @
b7b16f35
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
## 导入模块
## 导入模块
```
t
ypescript
```
t
s
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
)
获取
c
aptionsManager实例。
字幕配置管理,在调用CaptionsManager的方法前,需要先通过
[
accessibility.getCaptionsManager()
](
#accessibilitygetcaptionsmanager8
)
获取
C
aptionsManager实例。
**系统能力**
:以下各项对应的系统能力均为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
<
boolean
>
): void;
on(type: 'enableChange', callback: Callback
<
boolean
>
): void;
监听字幕配置启用状态变化事件。
监听字幕配置启用状态变化事件
,使用callback异步回调
。
**参数:**
**参数:**
...
@@ -170,18 +170,28 @@ on(type: 'enableChange', callback: Callback<boolean>): void;
...
@@ -170,18 +170,28 @@ on(type: 'enableChange', callback: Callback<boolean>): 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
<
CaptionsStyle
>
): void;
on(type: 'styleChange', callback: Callback
<
CaptionsStyle
>
): void;
监听字幕风格变化事件。
监听字幕风格变化事件
,使用callback异步回调
。
**参数:**
**参数:**
...
@@ -192,18 +202,28 @@ on(type: 'styleChange', callback: Callback<CaptionsStyle>): void;
...
@@ -192,18 +202,28 @@ on(type: 'styleChange', callback: Callback<CaptionsStyle>): 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
<
boolean
>
): void;
off(type: 'enableChange', callback?: Callback
<
boolean
>
): void;
取消监听字幕配置启用状态变化事件。
取消监听字幕配置启用状态变化事件
,使用callback异步回调
。
**参数:**
**参数:**
...
@@ -214,18 +234,28 @@ off(type: 'enableChange', callback?: Callback<boolean>): void;
...
@@ -214,18 +234,28 @@ off(type: 'enableChange', callback?: Callback<boolean>): 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
<
CaptionsStyle
>
): void;
off(type: 'styleChange', callback?: Callback
<
CaptionsStyle
>
): void;
取消字幕风格变化监听事件。
取消字幕风格变化监听事件
,使用callback异步回调
。
**参数:**
**参数:**
...
@@ -236,12 +266,22 @@ off(type: 'styleChange', callback?: Callback<CaptionsStyle>): void;
...
@@ -236,12 +266,22 @@ off(type: 'styleChange', callback?: Callback<CaptionsStyle>): 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)
**示例:**
**示例:**
```
t
ypescript
```
t
s
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
<
Array
<
AccessibilityAbilityInfo
>>
getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise
<
Array
<
AccessibilityAbilityInfo
>>
查询辅助应用列表,使用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<A
...
@@ -363,26 +408,39 @@ getAbilityLists(abilityType: AbilityType, stateType: AbilityState): Promise<A
**示例:**
**示例:**
```
typescript
```
ts
accessibility
.
getAbilityLists
(
"
spoken
"
,
"
enable
"
).
then
((
data
)
=>
{
let
abilityType
=
'
spoken
'
;
console
.
info
(
'
success data:getAbilityList1 :
'
+
JSON
.
stringify
(
data
));
let
abilityState
=
'
enable
'
;
for
(
let
item
of
data
)
{
let
abilityList
:
accessibility
.
AccessibilityInfo
[];
console
.
info
(
item
.
id
);
try
{
console
.
info
(
item
.
name
);
accessibility
.
getAbilityLists
(
abilityType
,
abilityState
).
then
((
data
)
=>
{
console
.
info
(
item
.
description
);
for
(
let
item
of
data
)
{
console
.
info
(
item
.
bundleName
);
console
.
info
(
item
.
id
);
}
console
.
info
(
item
.
name
);
}).
catch
((
err
)
=>
{
console
.
info
(
item
.
description
);
console
.
error
(
'
failed to getAbilityList1 because
'
+
JSON
.
stringify
(
err
));
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.getAbilityLists
## accessibility.getAbilityLists
<sup>(deprecated)</sup>
getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback
<
Array
<
AccessibilityAbilityInfo
>>
): void
getAbilityLists(abilityType: AbilityType, stateType: AbilityState,callback: AsyncCallback
<
Array
<
AccessibilityAbilityInfo
>>
): 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
'
;
if
(
err
)
{
let
abilityState
=
'
enable
'
;
console
.
error
(
'
failed to getAbilityList2 because
'
+
JSON
.
stringify
(
err
));
let
abilityList
:
accessibility
.
AccessibilityInfo
[];
return
;
try
{
}
accessibility
.
getAbilityLists
(
abilityType
,
abilityState
,
(
err
,
data
)
=>
{
console
.
info
(
'
success data:getAbilityList2 :
'
+
JSON
.
stringify
(
data
));
if
(
err
)
{
for
(
let
item
of
data
)
{
console
.
error
(
'
failed to get accessibility extension list because
'
+
JSON
.
stringify
(
err
));
console
.
info
(
item
.
id
);
return
;
console
.
info
(
item
.
name
);
}
console
.
info
(
item
.
description
);
for
(
let
item
of
data
)
{
console
.
info
(
item
.
bundleName
);
console
.
info
(
item
.
id
);
}
console
.
info
(
item
.
name
);
});
console
.
info
(
item
.
description
);
```
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
<
Array
<
AccessibilityAbilityInfo
>>
查询辅助应用列表,使用Promise异步回调。
**系统能力**
:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| abilityType |
[
AbilityType
](
#abilitytype
)
| 是 | 辅助应用的类型。 |
| stateType |
[
AbilityState
](
#abilitystate
)
| 是 | 辅助应用的状态。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
Array
<
[AccessibilityAbilityInfo](#accessibilityabilityinfo)
>>
| 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
<
Array
<
AccessibilityAbilityInfo
>>
): void
查询辅助应用列表,使用callback异步回调。
**系统能力**
:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| abilityType |
[
AbilityType
](
#abilitytype
)
| 是 | 辅助应用的类型。 |
| stateType |
[
AbilityState
](
#abilitystate
)
| 是 | 辅助应用的状态。 |
| callback | AsyncCallback
<
Array
<
[AccessibilityAbilityInfo](#accessibilityabilityinfo)
>>
| 是 | 回调函数,返回辅助应用信息列表。 |
**示例:**
```
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
**示例:**
**示例:**
```
t
ypescript
```
t
s
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
<
boolean
>
): void
on(type: 'accessibilityStateChange', callback: Callback
<
boolean
>
): void
监听辅助应用启用状态变化事件。
监听辅助应用启用状态变化事件
,使用callback异步回调
。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
...
@@ -448,17 +605,25 @@ on(type: 'accessibilityStateChange', callback: Callback<boolean>): void
...
@@ -448,17 +605,25 @@ on(type: 'accessibilityStateChange', callback: Callback<boolean>): 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
<
boolean
>
): void
on(type: 'touchGuideStateChange', callback: Callback
<
boolean
>
): void
监听触摸浏览功能启用状态变化事件。
监听触摸浏览功能启用状态变化事件
,使用callback异步回调
。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
...
@@ -471,17 +636,25 @@ on(type: 'touchGuideStateChange', callback: Callback<boolean>): void
...
@@ -471,17 +636,25 @@ on(type: 'touchGuideStateChange', callback: Callback<boolean>): 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
<
boolean
>
): void
off(type: 'accessibilityStateChange', callback?: Callback
<
boolean
>
): void
取消监听辅助应用启用状态变化事件。
取消监听辅助应用启用状态变化事件
,使用callback异步回调
。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
...
@@ -494,17 +667,25 @@ off(type: 'accessibilityStateChange', callback?: Callback<boolean>): void
...
@@ -494,17 +667,25 @@ off(type: 'accessibilityStateChange', callback?: Callback<boolean>): 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
<
boolean
>
): void
off(type: 'touchGuideStateChange', callback?: Callback
<
boolean
>
): void
取消监听触摸浏览启用状态变化事件。
取消监听触摸浏览启用状态变化事件
,使用callback异步回调
。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
**系统能力**
:以下各项对应的系统能力有所不同,详见下表。
...
@@ -517,10 +698,18 @@ off(type: 'touchGuideStateChange', callback?: Callback<boolean>): void
...
@@ -517,10 +698,18 @@ off(type: 'touchGuideStateChange', callback?: Callback<boolean>): 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<boolean>
...
@@ -539,7 +728,7 @@ isOpenAccessibility(): Promise<boolean>
**示例:**
**示例:**
```
t
ypescript
```
t
s
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<boolean>): void
...
@@ -563,7 +752,7 @@ isOpenAccessibility(callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
t
ypescript
```
t
s
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<boolean>
...
@@ -589,7 +778,7 @@ isOpenTouchGuide(): Promise<boolean>
**示例:**
**示例:**
```
t
ypescript
```
t
s
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<boolean>): void
...
@@ -613,7 +802,7 @@ isOpenTouchGuide(callback: AsyncCallback<boolean>): void
**示例:**
**示例:**
```
t
ypescript
```
t
s
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<void>
sendEvent(event: EventInfo): Promise<void>
发送无障碍事件, 使用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<void>
...
@@ -645,11 +839,11 @@ sendEvent(event: EventInfo): Promise<void>
**示例:**
**示例:**
```t
ypescript
```
t
s
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<void>): void
sendEvent(event: EventInfo, callback: AsyncCallback<void>): 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<void>): void
...
@@ -675,11 +874,11 @@ sendEvent(event: EventInfo, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```t
ypescript
```
t
s
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<void>
发送无障碍事件, 使用Promise异步回调。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| event | [EventInfo](#eventinfo) | 是 | 无障碍事件对象。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise<void> | 无返回结果的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<void>): void
发送无障碍事件, 使用callback异步回调。
**系统能力**:SystemCapability.BarrierFree.Accessibility.Core
**参数:**
| 参数名 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| event | [EventInfo](#eventinfo) | 是 | 辅助事件对象。 |
| callback | AsyncCallback<void> | 是 | 回调函数,如果发送无障碍事件失败,则 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));
}
```
zh-cn/application-dev/reference/apis/js-apis-application-AccessibilityExtensionAbility.md
浏览文件 @
b7b16f35
...
@@ -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
)
{
if
(
event
.
eventType
==
'
click
'
)
{
console
.
log
(
'
AxExtensionAbility onAccessibilityEvent
'
);
console
.
log
(
"
AxExtensionAbility onAccessibilityEvent: click
"
);
if
(
event
.
eventType
==
'
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
)
{
if
(
keyEvent
.
keyCode
==
22
)
{
console
.
log
(
'
AxExtensionAbility onKeyEvent
'
);
console
.
log
(
"
AxExtensionAbility onKeyEvent: intercept 22
"
);
if
(
keyEvent
.
keyCode
==
22
)
{
return
true
;
console
.
log
(
'
AxExtensionAbility onKeyEvent: intercept 22
'
);
return
true
;
}
return
false
;
}
}
return
false
;
};
};
```
```
zh-cn/application-dev/reference/errorcodes/errorcode-accessibility.md
0 → 100644
浏览文件 @
b7b16f35
# 无障碍子系统错误码
## 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录