Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
128a5f1d
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
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看板
未验证
提交
128a5f1d
编写于
8月 31, 2023
作者:
O
openharmony_ci
提交者:
Gitee
8月 31, 2023
浏览文件
操作
浏览文件
下载
差异文件
!23505 Accessibility ArkTS规范整改
Merge pull request !23505 from zhanghuiyu/master
上级
234bee6a
ee0424a0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
312 addition
and
257 deletion
+312
-257
zh-cn/application-dev/application-models/accessibilityextensionability.md
...n-dev/application-models/accessibilityextensionability.md
+3
-3
zh-cn/application-dev/reference/apis/js-apis-inner-application-accessibilityExtensionContext.md
...s-apis-inner-application-accessibilityExtensionContext.md
+309
-254
未找到文件。
zh-cn/application-dev/application-models/accessibilityextensionability.md
浏览文件 @
128a5f1d
...
...
@@ -40,7 +40,7 @@ AccessibilityExtensionAbility为无障碍扩展服务框架,允许三方开发
在已创建工程的ets文件夹下创建AccessibilityExtAbility文件夹,在该文件夹下创建AccessibilityExtAbility.ts文件,在新增的文件中加入以下代码:
```
typescript
import
AccessibilityExtensionAbility
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
AccessibilityExtensionAbility
,
{
AccessibilityEvent
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
class
AccessibilityExtAbility
extends
AccessibilityExtensionAbility
{
onConnect
()
{
...
...
@@ -51,7 +51,7 @@ class AccessibilityExtAbility extends AccessibilityExtensionAbility {
console
.
info
(
'
AccessibilityExtAbility onDisconnect
'
);
}
onAccessibilityEvent
(
accessibilityEvent
)
{
onAccessibilityEvent
(
accessibilityEvent
:
AccessibilityEvent
)
{
console
.
info
(
'
AccessibilityExtAbility onAccessibilityEvent:
'
+
JSON
.
stringify
(
accessibilityEvent
));
}
}
...
...
@@ -72,7 +72,7 @@ export default AccessibilityExtAbility;
相关无障碍事件可以在
`onAccessibilityEvent()`
方法中进行业务逻辑处理,具体事件可参考
[
AccessibilityEvent
](
../reference/apis/js-apis-application-accessibilityExtensionAbility.md#accessibilityevent
)
。此处以事件
`pageStateUpdate`
为例:
```
typescript
onAccessibilityEvent
(
accessibilityEvent
)
{
onAccessibilityEvent
(
accessibilityEvent
:
AccessibilityEvent
)
{
console
.
info
(
'
AccessibilityExtAbility onAccessibilityEvent:
'
+
JSON
.
stringify
(
accessibilityEvent
));
if
(
accessibilityEvent
.
eventType
===
'
pageStateUpdate
'
)
{
console
.
info
(
'
AccessibilityExtAbility onAccessibilityEvent: pageStateUpdate
'
);
...
...
zh-cn/application-dev/reference/apis/js-apis-inner-application-accessibilityExtensionContext.md
浏览文件 @
128a5f1d
...
...
@@ -15,13 +15,14 @@ AccessibilityExtensionContext是AccessibilityExtensionAbility上下文环境,
在使用AccessibilityExtensionContext的功能前,需要通过AccessibilityExtensionAbility子类实例获取AccessibilityExtensionContex的实例。
```
ts
import
AccessibilityExtensionAbility
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
axContext
;
import
AccessibilityExtensionAbility
,
{
AccessibilityExtensionContext
,
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
axContext
:
AccessibilityExtensionContext
;
class
EntryAbility
extends
AccessibilityExtensionAbility
{
onConnect
():
void
{
console
.
log
(
'
AxExtensionAbility onConnect
'
);
axContext
=
this
.
context
;
}
axContext
=
this
.
context
;
}
```
...
...
@@ -99,15 +100,16 @@ setTargetBundleName(targetNames: Array\<string>): Promise\<void>;
```
ts
let
targetNames
=
[
'
com.ohos.xyz
'
];
try
{
axContext
.
setTargetBundleName
(
targetNames
).
then
(()
=>
{
console
.
info
(
'
set target bundle names success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to set target bundle names, because
${
JSON
.
stringify
(
err
)}
`
);
});
axContext
.
setTargetBundleName
(
targetNames
).
then
(()
=>
{
console
.
info
(
'
set target bundle names success
'
);
}).
catch
((
err
:
object
)
=>
{
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
)}
`
);
}
;
console
.
error
(
`failed to set target bundle names, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
## AccessibilityExtensionContext.setTargetBundleName
...
...
@@ -128,18 +130,20 @@ setTargetBundleName(targetNames: Array\<string>, callback: AsyncCallback\<void>)
**示例:**
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
targetNames
=
[
'
com.ohos.xyz
'
];
try
{
axContext
.
setTargetBundleName
(
targetNames
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to set target bundle names, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
set target bundle names success
'
);
});
axContext
.
setTargetBundleName
(
targetNames
,
(
err
:
BusinessError
<
void
>
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to set target bundle names, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
set target bundle names success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to set target bundle names, because
${
JSON
.
stringify
(
exception
)}
`
);
}
;
console
.
error
(
`failed to set target bundle names, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
## AccessibilityExtensionContext.getFocusElement
...
...
@@ -173,16 +177,18 @@ getFocusElement(isAccessibilityFocus?: boolean): Promise\<AccessibilityElement>;
**示例:**
```
ts
let
focusElement
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
focusElement
:
AccessibilityElement
;
try
{
axContext
.
getFocusElement
().
then
((
data
)
=>
{
focusElement
=
data
;
console
.
log
(
'
get focus element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
err
)}
`
);
});
axContext
.
getFocusElement
().
then
((
data
:
AccessibilityElement
)
=>
{
focusElement
=
data
;
console
.
log
(
'
get focus element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -211,18 +217,21 @@ getFocusElement(callback: AsyncCallback\<AccessibilityElement>): void;
**示例:**
```
ts
let
focusElement
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
focusElement
:
AccessibilityElement
;
try
{
axContext
.
getFocusElement
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
focusElement
=
data
;
console
.
info
(
'
get focus element success
'
);
});
axContext
.
getFocusElement
((
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
focusElement
=
data
;
console
.
info
(
'
get focus element success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -252,19 +261,23 @@ getFocusElement(isAccessibilityFocus: boolean, callback: AsyncCallback\<Accessib
**示例:**
```
ts
let
focusElement
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
focusElement
:
AccessibilityElement
;
let
isAccessibilityFocus
=
true
;
try
{
axContext
.
getFocusElement
(
isAccessibilityFocus
,
(
err
,
data
)
=>
{
axContext
.
getFocusElement
(
isAccessibilityFocus
,
(
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
focusElement
=
data
;
console
.
info
(
'
get focus element success
'
);
});
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get focus element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
## AccessibilityExtensionContext.getWindowRootElement
...
...
@@ -298,16 +311,18 @@ getWindowRootElement(windowId?: number): Promise\<AccessibilityElement>;
**示例:**
```
ts
let
rootElement
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
rootElement
:
AccessibilityElement
;
try
{
axContext
.
getWindowRootElement
().
then
((
data
)
=>
{
rootElement
=
data
;
console
.
log
(
'
get root element of the window success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
err
)}
`
);
});
axContext
.
getWindowRootElement
().
then
((
data
:
AccessibilityElement
)
=>
{
rootElement
=
data
;
console
.
log
(
'
get root element of the window success
'
);
}).
catch
((
err
:
object
)
=>
{
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
)}
`
);
console
.
error
(
`failed to get root element of the window,
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -336,18 +351,22 @@ getWindowRootElement(callback: AsyncCallback\<AccessibilityElement>): void;
**示例:**
```
ts
let
rootElement
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
rootElement
:
AccessibilityElement
;
try
{
axContext
.
getWindowRootElement
((
err
,
data
)
=>
{
axContext
.
getWindowRootElement
((
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
rootElement
=
data
;
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
)}
`
);
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -377,19 +396,23 @@ getWindowRootElement(windowId: number, callback: AsyncCallback\<AccessibilityEle
**示例:**
```
ts
let
rootElement
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
rootElement
:
AccessibilityElement
;
let
windowId
=
10
;
try
{
axContext
.
getWindowRootElement
(
windowId
,
(
err
,
data
)
=>
{
axContext
.
getWindowRootElement
(
windowId
,
(
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
rootElement
=
data
;
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
)}
`
);
console
.
error
(
`failed to get root element of the window, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -424,16 +447,18 @@ getWindows(displayId?: number): Promise\<Array\<AccessibilityElement>>;
**示例:**
```
ts
let
windows
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
windows
:
AccessibilityElement
[];
try
{
axContext
.
getWindows
().
then
((
data
)
=>
{
windows
=
data
;
console
.
log
(
'
get windows success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
err
)}
`
);
});
axContext
.
getWindows
().
then
((
data
:
AccessibilityElement
[]
)
=>
{
windows
=
data
;
console
.
log
(
'
get windows success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -462,18 +487,21 @@ getWindows(callback: AsyncCallback\<Array\<AccessibilityElement>>): void;
**示例:**
```
ts
let
windows
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
windows
:
AccessibilityElement
[];
try
{
axContext
.
getWindows
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
windows
=
data
;
console
.
info
(
'
get windows success
'
);
});
axContext
.
getWindows
((
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
[]
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
windows
=
data
;
console
.
info
(
'
get windows success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -503,19 +531,22 @@ getWindows(displayId: number, callback: AsyncCallback\<Array\<AccessibilityEleme
**示例:**
```
ts
let
windows
;
import
{
AccessibilityElement
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
windows
:
AccessibilityElement
[];
let
displayId
=
10
;
try
{
axContext
.
getWindows
(
displayId
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
windows
=
data
;
console
.
info
(
'
get windows success
'
);
});
axContext
.
getWindows
(
displayId
,
(
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
[]
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
windows
=
data
;
console
.
info
(
'
get windows success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get windows, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
...
...
@@ -552,19 +583,20 @@ injectGesture(gesturePath: GesturePath): Promise\<void>;
```
ts
import
GesturePath
from
'
@ohos.accessibility.GesturePath
'
;
import
GesturePoint
from
'
@ohos.accessibility.GesturePoint
'
;
let
gesturePath
=
new
GesturePath
.
GesturePath
(
100
);
let
gesturePath
:
GesturePath
.
GesturePath
=
new
GesturePath
.
GesturePath
(
100
);
try
{
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
let
gesturePoint
=
new
GesturePoint
.
GesturePoint
(
100
,
i
*
200
);
gesturePath
.
points
.
push
(
gesturePoint
);
}
axContext
.
injectGesture
(
gesturePath
).
then
(()
=>
{
console
.
info
(
'
inject gesture success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
err
)}
`
);
});
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
let
gesturePoint
=
new
GesturePoint
.
GesturePoint
(
100
,
i
*
200
);
gesturePath
.
points
.
push
(
gesturePoint
);
}
axContext
.
injectGesture
(
gesturePath
).
then
(()
=>
{
console
.
info
(
'
inject gesture success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
## AccessibilityExtensionContext.injectGesture
...
...
@@ -595,21 +627,22 @@ injectGesture(gesturePath: GesturePath, callback: AsyncCallback\<void>): void
```
ts
import
GesturePath
from
'
@ohos.accessibility.GesturePath
'
;
import
GesturePoint
from
'
@ohos.accessibility.GesturePoint
'
;
let
gesturePath
=
new
GesturePath
.
GesturePath
(
100
);
let
gesturePath
:
GesturePath
.
GesturePath
=
new
GesturePath
.
GesturePath
(
100
);
try
{
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
let
gesturePoint
=
new
GesturePoint
.
GesturePoint
(
100
,
i
*
200
);
gesturePath
.
points
.
push
(
gesturePoint
);
for
(
let
i
=
0
;
i
<
10
;
i
++
)
{
let
gesturePoint
=
new
GesturePoint
.
GesturePoint
(
100
,
i
*
200
);
gesturePath
.
points
.
push
(
gesturePoint
);
}
axContext
.
injectGesture
(
gesturePath
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
axContext
.
injectGesture
(
gesturePath
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
inject gesture success
'
);
});
console
.
info
(
'
inject gesture success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to inject gesture, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
## AccessibilityElement<sup>9+</sup>
...
...
@@ -635,12 +668,14 @@ attributeNames\<T extends keyof ElementAttributeValues>(): Promise\<Array\<T>>;
**示例:**
```
ts
let
attributeNames
;
rootElement
.
attributeNames
().
then
((
data
)
=>
{
console
.
log
(
'
get attribute names success
'
);
attributeNames
=
data
;
import
{
ElementAttributeKeys
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
attributeNames
:
ElementAttributeKeys
;
rootElement
.
attributeNames
().
then
((
data
:
ElementAttributeKeys
)
=>
{
console
.
log
(
'
get attribute names success
'
);
attributeNames
=
data
;
}).
catch
((
err
:
object
)
=>
{
console
.
log
(
`failed to get attribute names, because
${
JSON
.
stringify
(
err
)}
`
);
console
.
log
(
`failed to get attribute names, because
${
JSON
.
stringify
(
err
)}
`
);
});
```
### attributeNames
...
...
@@ -660,14 +695,17 @@ attributeNames\<T extends keyof ElementAttributeValues>(callback: AsyncCallback\
**示例:**
```
ts
let
attributeNames
;
rootElement
.
attributeNames
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get attribute names, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
attributeNames
=
data
;
console
.
info
(
'
get attribute names success
'
);
import
{
ElementAttributeKeys
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
attributeNames
:
ElementAttributeKeys
[];
rootElement
.
attributeNames
((
err
:
BusinessError
<
void
>
,
data
:
ElementAttributeKeys
[])
=>
{
if
(
err
)
{
console
.
error
(
`failed to get attribute names, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
attributeNames
=
data
;
console
.
info
(
'
get attribute names success
'
);
});
```
### attributeValue
...
...
@@ -682,7 +720,7 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ---- | ---- | -------- |
| attributeName |
T
| 是 | 表示属性的名称。 |
| attributeName |
ElementAttributeKeys
| 是 | 表示属性的名称。 |
**返回值:**
...
...
@@ -701,17 +739,19 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T): Promi
**示例:**
```
ts
let
attributeName
=
'
name
'
;
let
attributeValue
;
import
{
ElementAttributeKeys
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
attributeName
:
ElementAttributeKeys
=
'
bundleName
'
;
let
attributeValue
:
string
;
try
{
rootElement
.
attributeValue
(
attributeName
).
then
((
data
)
=>
{
console
.
log
(
'
get attribute value by name success
'
);
attributeValue
=
data
;
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
err
)}
`
);
});
rootElement
.
attributeValue
(
attributeName
).
then
((
data
:
string
)
=>
{
console
.
log
(
'
get attribute value by name success
'
);
attributeValue
=
data
;
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### attributeValue
...
...
@@ -727,7 +767,7 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ---------------------------------------- | ---- | ---------------------- |
| attributeName |
T
| 是 | 表示属性的名称。 |
| attributeName |
ElementAttributeKeys
| 是 | 表示属性的名称。 |
| callback | AsyncCallback
<
ElementAttributeValues[T]
>
| 是 | 回调函数,返回根据节点属性名称获取的属性值。 |
**错误码:**
...
...
@@ -741,19 +781,22 @@ attributeValue\<T extends keyof ElementAttributeValues>(attributeName: T,
**示例:**
```
ts
let
attributeValue
;
let
attributeName
=
'
name
'
;
import
{
ElementAttributeKeys
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
attributeName
:
ElementAttributeKeys
=
'
bundleName
'
;
let
attributeValue
:
string
;
try
{
rootElement
.
attributeValue
(
attributeName
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
attributeValue
=
data
;
console
.
info
(
'
get attribute value success
'
);
});
rootElement
.
attributeValue
(
attributeName
,
(
err
:
BusinessError
<
void
>
,
data
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
attributeValue
=
data
;
console
.
info
(
'
get attribute value success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to get attribute value, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### actionNames
...
...
@@ -773,13 +816,13 @@ actionNames(): Promise\<Array\<string>>;
**示例:**
```
ts
let
actionNames
;
rootElement
.
actionNames
().
then
((
data
)
=>
{
console
.
log
(
'
get action names success
'
);
actionNames
=
data
;
let
actionNames
:
string
[]
;
rootElement
.
actionNames
().
then
((
data
:
string
[]
)
=>
{
console
.
log
(
'
get action names success
'
);
actionNames
=
data
;
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to get action names because
${
JSON
.
stringify
(
err
)}
`
);
})
;
console
.
error
(
`failed to get action names because
${
JSON
.
stringify
(
err
)}
`
);
})
```
### actionNames
...
...
@@ -798,15 +841,15 @@ actionNames(callback: AsyncCallback\<Array\<string>>): void;
**示例:**
```
ts
let
actionNames
;
rootElement
.
actionNames
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get action names, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
actionNames
=
data
;
console
.
info
(
'
get action names success
'
);
})
;
let
actionNames
:
string
[]
;
rootElement
.
actionNames
((
err
:
BusinessError
<
void
>
,
data
:
string
[]
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to get action names, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
actionNames
=
data
;
console
.
info
(
'
get action names success
'
);
})
```
### performAction
...
...
@@ -840,14 +883,15 @@ performAction(actionName: string, parameters?: object): Promise\<void>;
**示例:**
```
ts
let
actionName
=
'
action
'
;
try
{
rootElement
.
performAction
(
'
action
'
).
then
((
data
)
=>
{
console
.
info
(
'
perform action success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
err
)}
`
);
});
rootElement
.
performAction
(
actionName
).
then
((
)
=>
{
console
.
info
(
'
perform action success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### performAction
...
...
@@ -876,16 +920,19 @@ performAction(actionName: string, callback: AsyncCallback\<void>): void;
**示例:**
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
actionName
=
'
action
'
;
try
{
rootElement
.
performAction
(
'
action
'
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
perform action success
'
);
});
rootElement
.
performAction
(
actionName
,
(
err
:
BusinessError
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
perform action success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### performAction
...
...
@@ -915,20 +962,22 @@ performAction(actionName: string, parameters: object, callback: AsyncCallback\<v
**示例:**
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
actionName
=
'
action
'
;
let
parameters
=
{
'
setText
'
:
'
test text
'
'
setText
'
:
'
test text
'
};
try
{
rootElement
.
performAction
(
actionName
,
parameters
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
perform action success
'
);
});
rootElement
.
performAction
(
actionName
,
parameters
,
(
err
:
BusinessError
<
void
>
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
console
.
info
(
'
perform action success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to perform action, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### findElement('content')
...
...
@@ -955,18 +1004,17 @@ findElement(type: 'content', condition: string): Promise\<Array\<AccessibilityEl
**示例:**
```
ts
let
type
=
'
content
'
;
let
condition
=
'
keyword
'
;
let
elements
;
let
elements
:
AccessibilityElement
[]
;
try
{
rootElement
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
elements
=
data
;
console
.
log
(
'
find element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
});
rootElement
.
findElement
(
'
content
'
,
condition
).
then
((
data
:
AccessibilityElement
[]
)
=>
{
elements
=
data
;
console
.
log
(
'
find element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### findElement('content')
...
...
@@ -988,20 +1036,21 @@ findElement(type: 'content', condition: string, callback: AsyncCallback\<Array\<
**示例:**
```
ts
let
type
=
'
content
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
condition
=
'
keyword
'
;
let
elements
;
let
elements
:
AccessibilityElement
[]
;
try
{
rootElement
.
findElement
(
type
,
condition
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
elements
=
data
;
console
.
info
(
'
find element success
'
);
});
rootElement
.
findElement
(
'
content
'
,
condition
,
(
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
[]
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
elements
=
data
;
console
.
info
(
'
find element success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### findElement('focusType')
...
...
@@ -1028,18 +1077,19 @@ findElement(type: 'focusType', condition: FocusType): Promise\<AccessibilityElem
**示例:**
```
ts
let
type
=
'
focusType
'
;
let
condition
=
'
normal
'
;
let
element
;
import
{
FocusType
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
condition
:
FocusType
=
'
normal
'
;
let
element
:
AccessibilityElement
;
try
{
rootElement
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
element
=
data
;
console
.
log
(
'
find element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
});
rootElement
.
findElement
(
'
focusType
'
,
condition
).
then
((
data
:
AccessibilityElement
)
=>
{
element
=
data
;
console
.
log
(
'
find element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### findElement('focusType')
...
...
@@ -1061,20 +1111,22 @@ findElement(type: 'focusType', condition: FocusType, callback: AsyncCallback\<Ac
**示例:**
```
ts
let
type
=
'
focusType
'
;
let
condition
=
'
normal
'
;
let
element
;
import
{
FocusType
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
condition
:
FocusType
=
'
normal
'
;
let
element
:
AccessibilityElement
;
try
{
rootElement
.
findElement
(
type
,
condition
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
element
=
data
;
console
.
info
(
'
find element success
'
);
});
rootElement
.
findElement
(
'
focusType
'
,
condition
,
(
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
element
=
data
;
console
.
info
(
'
find element success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### findElement('focusDirection')
...
...
@@ -1101,18 +1153,19 @@ findElement(type: 'focusDirection', condition: FocusDirection): Promise\<Accessi
**示例:**
```
ts
let
type
=
'
focusDirection
'
;
let
condition
=
'
up
'
;
let
element
;
import
{
FocusDirection
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
let
condition
:
FocusDirection
=
'
up
'
;
let
element
:
AccessibilityElement
;
try
{
rootElement
.
findElement
(
type
,
condition
).
then
((
data
)
=>
{
element
=
data
;
console
.
log
(
'
find element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
});
rootElement
.
findElement
(
'
focusDirection
'
,
condition
).
then
((
data
:
AccessibilityElement
)
=>
{
element
=
data
;
console
.
log
(
'
find element success
'
);
}).
catch
((
err
:
object
)
=>
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
### findElement('focusDirection')
...
...
@@ -1134,19 +1187,21 @@ findElement(type: 'focusDirection', condition: FocusDirection, callback: AsyncCa
**示例:**
```
ts
let
type
=
'
focusDirection
'
;
let
condition
=
'
up
'
;
let
elements
;
import
{
FocusDirection
}
from
'
@ohos.application.AccessibilityExtensionAbility
'
;
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
condition
:
FocusDirection
=
'
up
'
;
let
elements
:
AccessibilityElement
;
try
{
rootElement
.
findElement
(
type
,
condition
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
elements
=
data
;
console
.
info
(
'
find element success
'
);
});
rootElement
.
findElement
(
'
focusDirection
'
,
condition
,
(
err
:
BusinessError
<
void
>
,
data
:
AccessibilityElement
)
=>
{
if
(
err
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
err
)}
`
);
return
;
}
elements
=
data
;
console
.
info
(
'
find element success
'
);
});
}
catch
(
exception
)
{
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
console
.
error
(
`failed to find element, because
${
JSON
.
stringify
(
exception
)}
`
);
}
```
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录