Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
10180d90
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
10180d90
编写于
3月 09, 2023
作者:
O
openharmony_ci
提交者:
Gitee
3月 09, 2023
浏览文件
操作
浏览文件
下载
差异文件
!15793 common event文档整改monthly
Merge pull request !15793 from zhuhan/monthly
上级
37d9799e
e461cdaf
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
826 addition
and
22 deletion
+826
-22
zh-cn/application-dev/reference/apis/Readme-CN.md
zh-cn/application-dev/reference/apis/Readme-CN.md
+5
-1
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
+17
-11
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
...lication-dev/reference/apis/js-apis-commonEventManager.md
+14
-10
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventData.md
...ference/apis/js-apis-inner-commonEvent-commonEventData.md
+11
-0
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventPublishData.md
.../apis/js-apis-inner-commonEvent-commonEventPublishData.md
+13
-0
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md
...pis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md
+11
-0
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md
...e/apis/js-apis-inner-commonEvent-commonEventSubscriber.md
+750
-0
zh-cn/application-dev/website.md
zh-cn/application-dev/website.md
+5
-0
未找到文件。
zh-cn/application-dev/reference/apis/Readme-CN.md
浏览文件 @
10180d90
...
...
@@ -126,7 +126,11 @@
-
[
@ohos.notification (Notification模块)(待停用)
](
js-apis-notification.md
)
-
application
-
[
EventHub
](
js-apis-inner-application-eventHub.md
)
-
commonEvent
-
[
CommonEventData
](
js-apis-inner-commonEvent-commonEventData.md
)
-
[
CommonEventPublishData
](
js-apis-inner-commonEvent-commonEventPublishData.md
)
-
[
CommonEventSubscriber
](
js-apis-inner-commonEvent-commonEventSubscriber.md
)
-
[
CommonEventSubscribeInfo
](
js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
-
包管理
-
[
@ohos.bundle.appControl (appControl模块)
](
js-apis-appControl.md
)
-
[
@ohos.bundle.bundleManager (bundleManager模块)
](
js-apis-bundleManager.md
)
...
...
zh-cn/application-dev/reference/apis/js-apis-commonEvent.md
浏览文件 @
10180d90
...
...
@@ -171,7 +171,7 @@ CommonEvent模块支持的事件类型。名称指的是系统公共事件宏;
| COMMON_EVENT_SLOT_CHANGE
<sup>
9+
<sup>
| usual.event.SLOT_CHANGE | ohos.permission.NOTIFICATION_CONTROLLER | 表示通知通道更新的动作。 |
| COMMON_EVENT_SPN_INFO_CHANGED
<sup>
9+
<sup>
| usual.event.SPN_INFO_CHANGED | 无 | 表示spn显示信息已更新的公共事件的动作。 |
| COMMON_EVENT_QUICK_FIX_APPLY_RESULT
<sup>
9+
<sup>
| usual.event.QUICK_FIX_APPLY_RESULT | 无 | 指示快速修复应用的动作。 |
| COMMON_EVENT_USER_INFO_UPDATED
<sup>
9+
<sup>
| usual.event.USER_INFO_UPDATED | 无 | 表示用户信息已更新。|
## CommonEvent.publish
...
...
@@ -219,7 +219,7 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发布的公共事件。 |
| options |
[
CommonEventPublishData
](
#commoneventpublishdata
)
| 是 | 表示发布公共事件的属性。 |
| options |
[
CommonEventPublishData
](
./js-apis-inner-commonEvent-commonEventPublishData.md
)
| 是 | 表示发布公共事件的属性。 |
| callback | syncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**示例:**
...
...
@@ -303,7 +303,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发布的公共事件。 |
| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 |
| options |
[
CommonEventPublishData
](
#commoneventpublishdata
)
| 是 | 表示发布公共事件的属性。 |
| options |
[
CommonEventPublishData
](
./js-apis-inner-commonEvent-commonEventPublishData.md
)
| 是 | 表示发布公共事件的属性。 |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**示例:**
...
...
@@ -346,8 +346,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
#commoneventsubscribeinfo
)
| 是 | 表示订阅信息。 |
| callback | AsyncCallback
\<
[
CommonEventSubscriber
](
#commoneventsubscriber
)
> | 是 | 表示创建订阅者的回调方法。 |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
| 是 | 表示订阅信息。 |
| callback | AsyncCallback
\<
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
> | 是 | 表示创建订阅者的回调方法。 |
**示例:**
...
...
@@ -388,12 +388,12 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
#commoneventsubscribeinfo
)
| 是 | 表示订阅信息。 |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
| 是 | 表示订阅信息。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------------------------------- | ---------------- |
| Promise
\<
[
CommonEventSubscriber
](
#commoneventsubscriber
)
> | 返回订阅者对象。 |
| Promise
\<
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
> | 返回订阅者对象。 |
**示例:**
...
...
@@ -428,8 +428,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber |
[
CommonEventSubscriber
](
#commoneventsubscriber
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
[
CommonEventData
](
#commoneventdata
)
> | 是 | 表示接收公共事件数据的回调函数。 |
| subscriber |
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
[
CommonEventData
](
./js-apis-inner-commonEvent-commonEventData.md
)
> | 是 | 表示接收公共事件数据的回调函数。 |
**示例:**
...
...
@@ -480,7 +480,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber |
[
CommonEventSubscriber
](
#commoneventsubscriber
)
| 是 | 表示订阅者对象。 |
| subscriber |
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
void> | 否 | 表示取消订阅的回调方法。 |
**示例:**
...
...
@@ -526,6 +526,7 @@ function unsubscribeCallBack(err) {
//创建订阅者
CommonEvent
.
createSubscriber
(
subscribeInfo
,
createSubscriberCallBack
);
<<<<<<<
HEAD
//取消订阅公共事件
CommonEvent
.
unsubscribe
(
subscriber
,
unsubscribeCallBack
);
```
...
...
@@ -1278,4 +1279,9 @@ subscriber.finishCommonEvent().then(() => {
| publisherPermission | string | 是 | 否 | 表示发布者的权限。 |
| publisherDeviceId | string | 是 | 否 | 表示设备ID,该值必须是同一ohos网络上的现有设备ID。 |
| userId | number | 是 | 否 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 |
| priority | number | 是 | 否 | 表示订阅者的优先级。值的范围是-100到1000。 |
\ No newline at end of file
| priority | number | 是 | 否 | 表示订阅者的优先级。值的范围是-100到1000。 |
=======
// 取消订阅公共事件
CommonEvent.unsubscribe(subscriber, unsubscribeCB);
```
>>>>>>> a6c9265cd... common event docs fix
zh-cn/application-dev/reference/apis/js-apis-commonEventManager.md
浏览文件 @
10180d90
...
...
@@ -235,7 +235,7 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发布的公共事件。 |
| options |
[
CommonEventPublishData
](
#commoneventpublishdata
)
| 是 | 表示发布公共事件的属性。 |
| options |
[
CommonEventPublishData
](
./js-apis-inner-commonEvent-commonEventPublishData.md
)
| 是 | 表示发布公共事件的属性。 |
| callback | syncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**错误码:**
...
...
@@ -344,7 +344,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
| -------- | ---------------------- | ---- | ---------------------- |
| event | string | 是 | 表示要发布的公共事件。 |
| userId | number | 是 | 表示指定向该用户ID发送此公共事件。 |
| options |
[
CommonEventPublishData
](
#commoneventpublishdata
)
| 是 | 表示发布公共事件的属性。 |
| options |
[
CommonEventPublishData
](
./js-apis-inner-commonEvent-commonEventPublishData.md
)
| 是 | 表示发布公共事件的属性。 |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**错误码:**
...
...
@@ -399,8 +399,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
#commoneventsubscribeinfo
)
| 是 | 表示订阅信息。 |
| callback | AsyncCallback
\<
[
CommonEventSubscriber
](
#commoneventsubscriber
)
> | 是 | 表示创建订阅者的回调方法。 |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
| 是 | 表示订阅信息。 |
| callback | AsyncCallback
\<
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
> | 是 | 表示创建订阅者的回调方法。 |
**示例:**
...
...
@@ -445,12 +445,12 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
| 参数名 | 类型 | 必填 | 说明 |
| ------------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
#commoneventsubscribeinfo
)
| 是 | 表示订阅信息。 |
| subscribeInfo |
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
| 是 | 表示订阅信息。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------------------------------- | ---------------- |
| Promise
\<
[
CommonEventSubscriber
](
#commoneventsubscriber
)
> | 返回订阅者对象。 |
| Promise
\<
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
> | 返回订阅者对象。 |
**示例:**
...
...
@@ -490,8 +490,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ---------------------------------------------------- | ---- | -------------------------------- |
| subscriber |
[
CommonEventSubscriber
](
#commoneventsubscriber
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
[
CommonEventData
](
#commoneventdata
)
> | 是 | 表示接收公共事件数据的回调函数。 |
| subscriber |
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
[
CommonEventData
](
./js-apis-inner-commonEvent-commonEventData.md
)
> | 是 | 表示接收公共事件数据的回调函数。 |
**示例:**
...
...
@@ -551,7 +551,7 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
| 参数名 | 类型 | 必填 | 说明 |
| ---------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber |
[
CommonEventSubscriber
](
#commoneventsubscriber
)
| 是 | 表示订阅者对象。 |
| subscriber |
[
CommonEventSubscriber
](
./js-apis-inner-commonEvent-commonEventSubscriber.md
)
| 是 | 表示订阅者对象。 |
| callback | AsyncCallback
\<
void> | 否 | 表示取消订阅的回调方法。 |
**示例:**
...
...
@@ -606,6 +606,7 @@ try {
}
catch
(
err
)
{
console
.
info
(
"
unsubscribe failed
"
+
JSON
.
stringify
(
err
));
}
<<<<<<<
HEAD
```
## CommonEventSubscriber
...
...
@@ -1350,4 +1351,7 @@ subscriber.finishCommonEvent().then(() => {
| publisherPermission | string | 是 | 否 | 表示发布者的权限。 |
| publisherDeviceId | string | 是 | 否 | 表示设备ID,该值必须是同一ohos网络上的现有设备ID。 |
| userId | number | 是 | 否 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 |
| priority | number | 是 | 否 | 表示订阅者的优先级。值的范围是-100到1000。 |
\ No newline at end of file
| priority | number | 是 | 否 | 表示订阅者的优先级。值的范围是-100到1000。 |
=======
```
>>>>>>> a6c9265cd... common event docs fix
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventData.md
0 → 100644
浏览文件 @
10180d90
# CommonEventData
**系统能力:**
`SystemCapability.Notification.CommonEvent`
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------- |-------------------- | ---- | ---- | ------------------------------------------------------- |
| event | string | 是 | 否 | 表示当前接收的公共事件名称。 |
| bundleName | string | 是 | 否 | 表示包名称。 |
| code | number | 是 | 否 | 表示公共事件的结果代码,用于传递int类型的数据。 |
| data | string | 是 | 否 | 表示公共事件的自定义结果数据,用于传递string类型的数据。 |
| parameters | {[key: string]: any} | 是 | 否 | 表示公共事件的附加信息。 |
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventPublishData.md
0 → 100644
浏览文件 @
10180d90
# CommonEventPublishData
**系统能力:**
`SystemCapability.Notification.CommonEvent`
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------------------- | -------------------- | ---- | ---- | ---------------------------- |
| bundleName | string | 是 | 否 | 表示包名称。 |
| code | number | 是 | 否 | 表示公共事件的结果代码。 |
| data | string | 是 | 否 | 表示公共事件的自定义结果数据。 |
| subscriberPermissions | Array
\<
string> | 是 | 否 | 表示订阅者的权限。 |
| isOrdered | boolean | 是 | 否 | 表示是否是有序事件。 |
| isSticky | boolean | 是 | 否 | 表示是否是粘性事件。仅系统应用或系统服务允许发送粘性事件。 |
| parameters | {[key: string]: any} | 是 | 否 | 表示公共事件的附加信息。 |
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md
0 → 100644
浏览文件 @
10180d90
# CommonEventSubscribeInfo
**系统能力:**
`SystemCapability.Notification.CommonEvent`
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| events | Array
\<
string> | 是 | 否 | 表示要发送的公共事件。 |
| publisherPermission | string | 是 | 否 | 表示发布者的权限。 |
| publisherDeviceId | string | 是 | 否 | 表示设备ID,该值必须是同一ohos网络上的现有设备ID。 |
| userId | number | 是 | 否 | 表示用户ID。此参数是可选的,默认值当前用户的ID。如果指定了此参数,则该值必须是系统中现有的用户ID。 |
| priority | number | 是 | 否 | 表示订阅者的优先级。值的范围是-100到1000。 |
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md
0 → 100644
浏览文件 @
10180d90
# CommonEventSubscriber
## getCode
```
ts
getCode
(
callback
:
AsyncCallback
<
number
>
):
void
```
以回调形式获取公共事件代码。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback
\<
number
\>
| 是 | 公共事件代码。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//获取有序公共事件代码回调
function
getCodeCB
(
err
,
code
)
{
if
(
err
.
code
)
{
console
.
error
(
`getCode failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
getCode
"
+
JSON
.
stringify
(
code
));
}
}
subscriber
.
getCode
(
getCodeCB
);
```
## getCode
```
ts
getCode
():
Promise
<
number
>
```
以Promise形式获取公共事件代码。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
number> | 公共事件代码。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
getCode
().
then
((
code
)
=>
{
console
.
info
(
"
getCode
"
+
JSON
.
stringify
(
code
));
}).
catch
((
err
)
=>
{
console
.
error
(
`getCode failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## setCode
```
ts
setCode
(
code
:
number
,
callback
:
AsyncCallback
<
void
>
):
void
```
以回调形式设置公共事件的代码。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | 是 | 公共事件的代码。 |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//设置有序公共事件的代码回调
function
setCodeCB
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`setCode failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
setCode
"
);
}
}
subscriber
.
setCode
(
1
,
setCodeCB
);
```
## setCode
```
ts
setCode
(
code
:
number
):
Promise
<
void
>
```
以Promise形式设置公共事件的代码。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ------------------ |
| code | number | 是 | 公共事件的代码。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
void> | 返回一个Promise的结果。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
setCode
(
1
).
then
(()
=>
{
console
.
info
(
"
setCode
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
`setCode failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## getData
```
ts
getData
(
callback
:
AsyncCallback
<
string
>
):
void
```
以回调形式获取公共事件的数据。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback
\<
string> | 是 | 公共事件的数据。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//获取有序公共事件代码数据回调
function
getDataCB
(
err
,
data
)
{
if
(
err
.
code
)
{
console
.
error
(
`getData failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
getData
"
+
JSON
.
stringify
(
data
));
}
}
subscriber
.
getData
(
getDataCB
);
```
## getData
```
ts
getData
():
Promise
<
string
>
```
以Promise形式获取公共事件的数据。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ---------------- | ------------------ |
| Promise
\<
string> | 公共事件的数据。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
getData
().
then
((
data
)
=>
{
console
.
info
(
"
getData
"
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
error
(
`getData failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## setData
setData(data: string, callback: AsyncCallback
\<
void>): void
以回调形式设置公共事件的数据。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- |
| data | string | 是 | 公共事件的数据。 |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function
setDataCB
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`setCode failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
setData
"
);
}
}
subscriber
.
setData
(
"
publish_data_changed
"
,
setDataCB
);
```
## setData
```
ts
setData
(
data
:
string
):
Promise
<
void
>
```
以Promise形式设置公共事件的果数据。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------- |
| data | string | 是 | 公共事件的数据。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
void> | 返回一个Promise的结果。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
setData
(
"
publish_data_changed
"
).
then
(()
=>
{
console
.
info
(
"
setData
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
`setCode failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## setCodeAndData
```
ts
setCodeAndData
(
code
:
number
,
data
:
string
,
callback
:
AsyncCallback
<
void
>
):
void
```
以回调形式设置公共事件代码和数据。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | 是 | 公共事件的代码。 |
| data | string | 是 | 公共事件的数据。 |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//设置有序公共事件的代码和数据回调
function
setCodeDataCB
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`setCodeAndData failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
setCodeDataCallback
"
);
}
}
subscriber
.
setCodeAndData
(
1
,
"
publish_data_changed
"
,
setCodeDataCB
);
```
## setCodeAndData
```
ts
setCodeAndData
(
code
:
number
,
data
:
string
):
Promise
<
void
>
```
以Promise形式设置公共事件的代码和数据。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | -------------------- |
| code | number | 是 | 公共事件的代码。 |
| data | string | 是 | 公共事件的数据。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
void> | 返回一个Promise。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
setCodeAndData
(
1
,
"
publish_data_changed
"
).
then
(()
=>
{
console
.
info
(
"
setCodeAndData
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
`setCodeAndData failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## isOrderedCommonEvent
```
ts
isOrderedCommonEvent
(
callback
:
AsyncCallback
<
boolean
>
):
void
```
以回调形式查询当前公共事件的是否为有序公共事件。
返回true代表是有序公共事件,false代表不是有序公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback
\<
boolean> | 是 | 当前公共事件的是否为有序公共事件。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//获取当前公共事件是否为有序事件的回调
function
isOrderedCB
(
err
,
isOrdered
)
{
if
(
err
.
code
)
{
console
.
error
(
`isOrderedCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
isOrdered
"
+
JSON
.
stringify
(
isOrdered
));
}
}
subscriber
.
isOrderedCommonEvent
(
isOrderedCB
);
```
## isOrderedCommonEvent
```
ts
isOrderedCommonEvent
():
Promise
<
boolean
>
```
以Promise形式查询当前公共事件的是否为有序公共事件。
返回true代表是有序公共事件,false代表不是有序公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ----------------- | -------------------------------- |
| Promise
\<
boolean> | 当前公共事件的是否为有序公共事件。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
isOrderedCommonEvent
().
then
((
isOrdered
)
=>
{
console
.
info
(
"
isOrdered
"
+
JSON
.
stringify
(
isOrdered
));
}).
catch
((
err
)
=>
{
console
.
error
(
`isOrdered failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## isStickyCommonEvent
```
ts
isStickyCommonEvent
(
callback
:
AsyncCallback
<
boolean
>
):
void
```
以回调形式检查当前公共事件是否为一个粘性事件。
返回true代表是粘性公共事件,false代表不是粘性公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback
\<
boolean> | 是 | 当前公共事件的是否为粘性公共事件。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//获取当前公共事件是否为粘性事件的回调
function
isStickyCB
(
err
,
isSticky
)
{
if
(
err
.
code
)
{
console
.
error
(
`isStickyCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
isSticky
"
+
JSON
.
stringify
(
isSticky
));
}
}
subscriber
.
isStickyCommonEvent
(
isStickyCB
);
```
## isStickyCommonEvent
```
ts
isStickyCommonEvent
():
Promise
<
boolean
>
```
以Promise形式检查当前公共事件是否为一个粘性事件。
返回true代表是粘性公共事件,false代表不是粘性公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ----------------- | -------------------------------- |
| Promise
\<
boolean> | 当前公共事件的是否为粘性公共事件。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
isStickyCommonEvent
().
then
((
isSticky
)
=>
{
console
.
info
(
"
isSticky
"
+
JSON
.
stringify
(
isSticky
));
}).
catch
((
err
)
=>
{
console
.
error
(
`isSticky failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## abortCommonEvent
```
ts
abortCommonEvent
(
callback
:
AsyncCallback
<
void
>
):
void
```
以回调形式取消当前的有序公共事件,取消后,有序公共事件不再向下一个订阅者传递。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback
\<
void> | 是 | 取消当前的有序公共事件。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//取消当前有序公共事件的回调
function
abortCB
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`abortCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
abortCommonEvent
"
);
}
}
subscriber
.
abortCommonEvent
(
abortCB
);
```
## abortCommonEvent
```
ts
abortCommonEvent
():
Promise
<
void
>
```
以Promise形式取消当前的有序公共事件,取消后,公共事件不再向下一个订阅者传递。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
void> | 返回一个Promise的结果。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
abortCommonEvent
().
then
(()
=>
{
console
.
info
(
"
abortCommonEvent
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
`abortCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## clearAbortCommonEvent
```
ts
clearAbortCommonEvent
(
callback
:
AsyncCallback
<
void
>
):
void
```
以回调形式清除当前有序公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback
\<
void> | 是 | 表示被指定的回调方法。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//清除当前公共事件取消状态的回调
function
clearAbortCB
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`clearAbortCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
clearAbortCommonEvent
"
);
}
}
subscriber
.
clearAbortCommonEvent
(
clearAbortCB
);
```
## clearAbortCommonEvent
```
ts
clearAbortCommonEvent
():
Promise
<
void
>
```
以Promise形式清除当前有序公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
void> | 返回一个Promise的结果。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
clearAbortCommonEvent
().
then
(()
=>
{
console
.
info
(
"
clearAbortCommonEvent
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
`clearAbortCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## getAbortCommonEvent
```
ts
getAbortCommonEvent
(
callback
:
AsyncCallback
<
boolean
>
):
void
```
以回调形式获取当前有序公共事件是否取消的状态。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback
\<
boolean> | 是 | 表示当前有序公共事件是否取消的状态。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//获取当前有序公共事件是否取消的回调
function
getAbortCB
(
err
,
abortEvent
)
{
if
(
err
.
code
)
{
console
.
error
(
`getAbortCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
abortCommonEvent
"
+
abortEvent
)
}
}
subscriber
.
getAbortCommonEvent
(
getAbortCB
);
```
## getAbortCommonEvent
```
ts
getAbortCommonEvent
():
Promise
<
boolean
>
```
以Promise形式获取当前有序公共事件是否取消的状态。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ----------------- | ---------------------------------- |
| Promise
\<
boolean> | 表示当前有序公共事件是否取消的状态。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
getAbortCommonEvent
().
then
((
abortEvent
)
=>
{
console
.
info
(
"
abortCommonEvent
"
+
JSON
.
stringify
(
abortEvent
));
}).
catch
((
err
)
=>
{
console
.
error
(
`getAbortCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## getSubscribeInfo
```
ts
getSubscribeInfo
(
callback
:
AsyncCallback
<
CommonEventSubscribeInfo
>
):
void
```
以回调形式获取订阅者的订阅信息。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback
\<
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
> | 是 | 表示订阅者的订阅信息。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//获取订阅者信息回调
function
getCB
(
err
,
subscribeInfo
)
{
if
(
err
.
code
)
{
console
.
error
(
`getSubscribeInfo failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
subscribeInfo
"
+
JSON
.
stringify
(
subscribeInfo
));
}
}
subscriber
.
getSubscribeInfo
(
getCB
);
```
## getSubscribeInfo
```
ts
getSubscribeInfo
():
Promise
<
CommonEventSubscribeInfo
>
```
以Promise形式获取订阅者的订阅信息。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------------ | ---------------------- |
| Promise
\<
[
CommonEventSubscribeInfo
](
./js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
> | 表示订阅者的订阅信息。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
getSubscribeInfo
().
then
((
subscribeInfo
)
=>
{
console
.
info
(
"
subscribeInfo
"
+
JSON
.
stringify
(
subscribeInfo
));
}).
catch
((
err
)
=>
{
console
.
error
(
`getSubscribeInfo failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
## finishCommonEvent<sup>9+</sup>
```
ts
finishCommonEvent
(
callback
:
AsyncCallback
<
void
>
):
void
```
以回调形式结束当前有序公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback
\<
void> | 是 | 表示有序公共事件结束后的回调函数。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
//结束当前有序公共事件的回调
function
finishCB
(
err
)
{
if
(
err
.
code
)
{
console
.
error
(
`finishCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
}
else
{
console
.
info
(
"
FinishCommonEvent
"
);
}
subscriber
.
finishCommonEvent
(
finishCB
);
```
## finishCommonEvent<sup>9+</sup>
```
ts
finishCommonEvent
():
Promise
<
void
\
>
```
以Promise形式结束当前有序公共事件。
**系统能力**
:
`SystemCapability.Notification.CommonEvent`
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise
\<
void> | 返回一个Promise的结果。 |
**示例:**
```
ts
let
subscriber
;
//创建成功的订阅者对象
subscriber
.
finishCommonEvent
().
then
(()
=>
{
console
.
info
(
"
FinishCommonEvent
"
);
}).
catch
((
err
)
=>
{
console
.
error
(
`finishCommonEvent failed, code is
${
err
.
code
}
, message is
${
err
.
message
}
`
);
});
```
\ No newline at end of file
zh-cn/application-dev/website.md
浏览文件 @
10180d90
...
...
@@ -928,6 +928,11 @@
-
[
@ohos.notification (Notification模块)(待停用)
](
reference/apis/js-apis-notification.md
)
-
application
-
[
EventHub
](
reference/apis/js-apis-inner-application-eventHub.md
)
-
commonEvent
-
[
CommonEventData
](
reference/apis/js-apis-inner-commonEvent-commonEventData.md
)
-
[
CommonEventPublishData
](
reference/apis/js-apis-inner-commonEvent-commonEventPublishData.md
)
-
[
CommonEventSubscriber
](
reference/apis/js-apis-inner-commonEvent-commonEventSubscriber.md
)
-
[
CommonEventSubscribeInfo
](
reference/apis/js-apis-inner-commonEvent-commonEventSubscribeInfo.md
)
-
包管理
-
[
@ohos.bundle.appControl (appControl模块)
](
reference/apis/js-apis-appControl.md
)
-
[
@ohos.bundle.bundleManager (bundleManager模块)
](
reference/apis/js-apis-bundleManager.md
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录