提交 c2a608d8 编写于 作者: X xuzhihao

Merge children docs into CommnEvent & Notificication

Signed-off-by: Nxuzhihao <xuzhihao16@huawei.com>
上级 f56d331b
# 公共事件模块 # 公共事件模块
> **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 权限列表 ## 权限列表
...@@ -208,7 +208,7 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\ ...@@ -208,7 +208,7 @@ publish(event: string, options: CommonEventPublishData, callback: AsyncCallback\
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| -------- | -------- | ---------------------- | ---- | ---------------------- | | -------- | -------- | ---------------------- | ---- | ---------------------- |
| event | 只读 | string | 是 | 表示要发布的公共事件。 | | event | 只读 | string | 是 | 表示要发布的公共事件。 |
| options | 只读 | [CommonEventPublishData](./js-apis-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | | options | 只读 | [CommonEventPublishData](#commoneventpublishdata) | 是 | 表示发布公共事件的属性。 |
| callback | 只读 | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 | | callback | 只读 | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:** **示例:**
...@@ -288,7 +288,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca ...@@ -288,7 +288,7 @@ publishAsUser(event: string, userId: number, options: CommonEventPublishData, ca
| -------- | -------- | ---------------------- | ---- | ---------------------- | | -------- | -------- | ---------------------- | ---- | ---------------------- |
| event | 只读 | string | 是 | 表示要发布的公共事件。 | | event | 只读 | string | 是 | 表示要发布的公共事件。 |
| userId | 只读 | number | 是 | 表示指定向该用户ID发送此公共事件。 | | userId | 只读 | number | 是 | 表示指定向该用户ID发送此公共事件。 |
| options | 只读 | [CommonEventPublishData](./js-apis-commonEventPublishData.md) | 是 | 表示发布公共事件的属性。 | | options | 只读 | [CommonEventPublishData](#commoneventpublishdata) | 是 | 表示发布公共事件的属性。 |
| callback | 只读 | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 | | callback | 只读 | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:** **示例:**
...@@ -331,8 +331,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac ...@@ -331,8 +331,8 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo, callback: AsyncCallbac
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- | | ------------- | -------- | ------------------------------------------------------------ | ---- | -------------------------- |
| subscribeInfo | 只读 | [CommonEventSubscribeInfo](./js-apis-commonEventSubscribeInfo.md) | 是 | 表示订阅信息。 | | subscribeInfo | 只读 | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | 是 | 表示订阅信息。 |
| callback | 只读 | AsyncCallback\<[CommonEventSubscriber](./js-apis-commonEventSubscriber.md)> | 是 | 表示创建订阅者的回调方法。 | | callback | 只读 | AsyncCallback\<[CommonEventSubscriber](#commoneventsubscriber)> | 是 | 表示创建订阅者的回调方法。 |
**示例:** **示例:**
...@@ -373,12 +373,12 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS ...@@ -373,12 +373,12 @@ createSubscriber(subscribeInfo: CommonEventSubscribeInfo): Promise\<CommonEventS
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ------------- | -------- | ----------------------------------------------------- | ---- | -------------- | | ------------- | -------- | ----------------------------------------------------- | ---- | -------------- |
| subscribeInfo | 只读 | [CommonEventSubscribeInfo](./js-apis-commonEventSubscribeInfo.md) | 是 | 表示订阅信息。 | | subscribeInfo | 只读 | [CommonEventSubscribeInfo](#commoneventsubscribeinfo) | 是 | 表示订阅信息。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------------------------------------------- | ---------------- | | --------------------------------------------------------- | ---------------- |
| Promise\<[CommonEventSubscriber](./js-apis-commonEventSubscriber.md)> | 返回订阅者对象。 | | Promise\<[CommonEventSubscriber](#commoneventsubscriber)> | 返回订阅者对象。 |
**示例:** **示例:**
...@@ -413,8 +413,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven ...@@ -413,8 +413,8 @@ subscribe(subscriber: CommonEventSubscriber, callback: AsyncCallback\<CommonEven
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- | | ---------- | -------- | --------------------------------------------------- | ---- | -------------------------------- |
| subscriber | 只读 | [CommonEventSubscriber](./js-apis-commonEventSubscriber.md) | 是 | 表示订阅者对象。 | | subscriber | 只读 | [CommonEventSubscriber](#commoneventsubscriber) | 是 | 表示订阅者对象。 |
| callback | 只读 | AsyncCallback\<[CommonEventData](./js-apis-commonEventData.md)> | 是 | 表示接收公共事件数据的回调函数。 | | callback | 只读 | AsyncCallback\<[CommonEventData](#commoneventdata)> | 是 | 表示接收公共事件数据的回调函数。 |
**示例:** **示例:**
...@@ -451,7 +451,7 @@ function CreateSubscriberCallBack(err, commonEventSubscriber) { ...@@ -451,7 +451,7 @@ function CreateSubscriberCallBack(err, commonEventSubscriber) {
CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
``` ```
## CommonEvent.unsubscribe ## CommonEvent.unsubscribe
...@@ -463,10 +463,10 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>): ...@@ -463,10 +463,10 @@ unsubscribe(subscriber: CommonEventSubscriber, callback?: AsyncCallback\<void>):
**参数:** **参数:**
| 名称 | 读写属性 | 类型 | 必填 | 描述 | | 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | --------------------- | ---- | ------------------------ | | ---------- | -------- | ----------------------------------------------- | ---- | ------------------------ |
| subscriber | 只读 | CommonEventSubscriber | 是 | 表示订阅者对象。 | | subscriber | 只读 | [CommonEventSubscriber](#commoneventsubscriber) | 是 | 表示订阅者对象。 |
| callback | 只读 | AsyncCallback\<void> | 否 | 表示取消订阅的回调方法。 | | callback | 只读 | AsyncCallback\<void> | 否 | 表示取消订阅的回调方法。 |
**示例:** **示例:**
...@@ -514,3 +514,742 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); ...@@ -514,3 +514,742 @@ CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack);
//取消订阅公共事件 //取消订阅公共事件
CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack); CommonEvent.unsubscribe(subscriber, UnsubscribeCallBack);
``` ```
## CommonEventSubscriber
### getCode
getCode(callback: AsyncCallback\<number>): void
获取公共事件的结果代码(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number> | 是 | 公共事件的结果代码。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getCodeCallback(err, Code) {
if (err.code) {
console.error("getCode failed " + JSON.stringify(err));
} else {
console.info("getCode " + JSON.stringify(Code));
}
}
subscriber.getCode(getCodeCallback);
```
### getCode
getCode(): Promise\<number>
获取公共事件的结果代码(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<number> | 公共事件的结果代码。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getCode().then((Code) => {
console.info("getCode " + JSON.stringify(Code));
}).catch((err) => {
console.error("getCode failed " + JSON.stringify(err));
});
```
### setCode
setCode(code: number, callback: AsyncCallback\<void>): void
设置公共事件的结果代码(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | 是 | 公共事件的结果代码。 |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function setCodeCallback(err) {
if (err.code) {
console.error("setCode failed " + JSON.stringify(err));
} else {
console.info("setCode");
}
}
subscriber.setCode(1, setCodeCallback);
```
### setCode
setCode(code: number): Promise\<void>
设置公共事件的结果代码(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| ------ | ------ | ---- | ------------------ |
| code | number | 是 | 公共事件的结果代码。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<void> | 返回一个Promise的结果。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.setCode(1).then(() => {
console.info("setCode");
}).catch((err) => {
console.error("setCode failed " + JSON.stringify(err));
});
```
### getData
getData(callback: AsyncCallback\<string>): void
获取公共事件的结果数据(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | 是 | 公共事件的结果数据。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getDataCallback(err, Data) {
if (err.code) {
console.error("getData failed " + JSON.stringify(err));
} else {
console.info("getData " + JSON.stringify(Data));
}
}
subscriber.getData(getDataCallback);
```
### getData
getData(): Promise\<string>
获取公共事件的结果数据(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | ------------------ |
| Promise\<string> | 公共事件的结果数据。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getData().then((Data) => {
console.info("getData " + JSON.stringify(Data));
}).catch((err) => {
console.error("getData failed " + JSON.stringify(err));
});
```
### setData
setData(data: string, callback: AsyncCallback\<void>): void
设置公共事件的结果数据(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------- |
| data | string | 是 | 公共事件的结果数据。 |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function setDataCallback(err) {
if (err.code) {
console.error("setData failed " + JSON.stringify(err));
} else {
console.info("setData");
}
}
subscriber.setData("publish_data_changed", setDataCallback);
```
### setData
setData(data: string): Promise\<void>
设置公共事件的结果数据(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| ------ | ------ | ---- | -------------------- |
| data | string | 是 | 公共事件的结果数据。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<void> | 返回一个Promise的结果。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.setData("publish_data_changed").then(() => {
console.info("setData");
}).catch((err) => {
console.error("setData failed " + JSON.stringify(err));
});
```
### setCodeAndData
setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void
设置公共事件的结果代码和结果数据(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | 是 | 公共事件的结果代码。 |
| data | string | 是 | 公共事件的结果数据。 |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function setCodeDataCallback(err) {
if (err.code) {
console.error("setCodeAndData failed " + JSON.stringify(err));
} else {
console.info("setCodeDataCallback");
}
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback);
```
### setCodeAndData
setCodeAndData(code: number, data: string): Promise\<void>
设置公共事件的结果代码和结果数据(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| ------ | ------ | ---- | -------------------- |
| code | number | 是 | 公共事件的结果代码。 |
| data | string | 是 | 公共事件的结果数据。 |
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<void> | 返回一个Promise的结果。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData");
}).catch((err) => {
console.info("setCodeAndData failed " + JSON.stringify(err));
});
```
### isOrderedCommonEvent
isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
查询当前公共事件的是否为有序公共事件(callback形式)。
返回true代表是有序公共事件,false代表不是有序公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 当前公共事件的是否为有序公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function isOrderedCallback(err, isOrdered) {
if (err.code) {
console.error("isOrderedCommonEvent failed " + JSON.stringify(err));
} else {
console.info("isOrdered " + JSON.stringify(isOrdered));
}
}
subscriber.isOrderedCommonEvent(isOrderedCallback);
```
### isOrderedCommonEvent
isOrderedCommonEvent(): Promise\<boolean>
查询当前公共事件的是否为有序公共事件(Promise形式)。
返回true代表是有序公共事件,false代表不是有序公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ----------------- | -------------------------------- |
| Promise\<boolean> | 当前公共事件的是否为有序公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
console.error("isOrdered failed " + JSON.stringify(err));
});
```
### isStickyCommonEvent
isStickyCommonEvent(callback: AsyncCallback\<boolean>): void
检查当前公共事件是否为一个粘性事件(callback形式)。
返回true代表是粘性公共事件,false代表不是粘性公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 当前公共事件的是否为粘性公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function isStickyCallback(err, isSticky) {
if (err.code) {
console.error("isStickyCommonEvent failed " + JSON.stringify(err));
} else {
console.info("isSticky " + JSON.stringify(isSticky));
}
}
subscriber.isStickyCommonEvent(isStickyCallback);
```
### isStickyCommonEvent
isStickyCommonEvent(): Promise\<boolean>
检查当前公共事件是否为一个粘性事件(callback形式)。
返回true代表是粘性公共事件,false代表不是粘性公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ----------------- | -------------------------------- |
| Promise\<boolean> | 当前公共事件的是否为粘性公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
console.error("isSticky failed " + JSON.stringify(err));
});
```
### abortCommonEvent
abortCommonEvent(callback: AsyncCallback\<void>): void
取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | 是 | 取消当前的公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function abortCallback(err) {
if (err.code) {
console.error("abortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("abortCommonEvent");
}
}
subscriber.abortCommonEvent(abortCallback);
```
### abortCommonEvent
abortCommonEvent(): Promise\<void>
取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<void> | 返回一个Promise的结果。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent");
}).catch((err) => {
console.error("abortCommonEvent failed " + JSON.stringify(err));
});
```
### clearAbortCommonEvent
clearAbortCommonEvent(callback: AsyncCallback\<void>): void
清除当前公共事件的取消状态,仅对有序公共事件有效(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function clearAbortCallback(err) {
if (err.code) {
console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("clearAbortCommonEvent");
}
}
subscriber.clearAbortCommonEvent(clearAbortCallback);
```
### clearAbortCommonEvent
clearAbortCommonEvent(): Promise\<void>
清除当前公共事件的取消状态,仅对有序公共事件有效(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<void> | 返回一个Promise的结果。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent");
}).catch((err) => {
console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
});
```
### getAbortCommonEvent
getAbortCommonEvent(callback: AsyncCallback\<boolean>): void
获取当前有序公共事件是否取消的状态(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 表示当前有序公共事件是否取消的状态。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getAbortCallback(err, AbortCommonEvent) {
if (err.code) {
console.error("getAbortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("AbortCommonEvent " + AbortCommonEvent)
}
}
subscriber.getAbortCommonEvent(getAbortCallback);
```
### getAbortCommonEvent
getAbortCommonEvent(): Promise\<boolean>
获取当前有序公共事件是否取消的状态(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ----------------- | ---------------------------------- |
| Promise\<boolean> | 表示当前有序公共事件是否取消的状态。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getAbortCommonEvent().then((AbortCommonEvent) => {
console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent));
}).catch((err) => {
console.error("getAbortCommonEvent failed " + JSON.stringify(err));
});
```
### getSubscribeInfo
getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void
获取订阅者的订阅信息(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 是 | 表示订阅者的订阅信息。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getSubscribeInfoCallback(err, SubscribeInfo) {
if (err.code) {
console.error("getSubscribeInfo failed " + JSON.stringify(err));
} else {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}
}
subscriber.getSubscribeInfo(getSubscribeInfoCallback);
```
### getSubscribeInfo
getSubscribeInfo(): Promise\<CommonEventSubscribeInfo>
获取订阅者的订阅信息(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------------ | ---------------------- |
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 表示订阅者的订阅信息。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getSubscribeInfo().then((SubscribeInfo) => {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}).catch((err) => {
console.error("getSubscribeInfo failed " + JSON.stringify(err));
});
```
### finishCommonEvent
finishCommonEvent(callback: AsyncCallback\<void\>): void
结束当前已排序的公共事件(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | 是 | 表示排序的公共事件结束后的回调函数。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
function finishCommonEventCallback() {
console.log("--------- finishCommonEventCallback ----------");
}
subscriber.finishCommonEvent(finishCommonEventCallback);
```
### finishCommonEvent
finishCommonEvent(): Promise\<void\>
结束当前已排序的公共事件(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<void> | 返回一个Promise的结果。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.finishCommonEvent()
.then(() => {
console.info("--------- finishCommonEventCallback ----------");
})
```
## CommonEventData
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- |
| event | 只读 | string | 是 | 表示当前接收的公共事件名称。 |
| bundleName | 只读 | string | 否 | 表示包名称。 |
| code | 只读 | number | 否 | 表示公共事件的结果代码,用于传递int类型的数据。 |
| data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string类型的数据。 |
| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息。 |
## CommonEventPublishData
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------------------- | -------- | -------------------- | ---- | ---------------------------- |
| bundleName | 只读 | string | 否 | 表示包名称。 |
| code | 只读 | number | 否 | 表示公共事件的结果代码。 |
| data | 只读 | string | 否 | 表示公共事件的自定义结果数据。 |
| subscriberPermissions | 只读 | Array\<string> | 否 | 表示订阅者的权限。 |
| isOrdered | 只读 | boolean | 否 | 表示是否是有序事件。 |
| isSticky | 只读 | boolean | 否 | 表示是否是粘性事件。 |
| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息。 |
## 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
# 公共事件数据
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## CommonEventData
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| ---------- | -------- | -------------------- | ---- | ------------------------------------------------------- |
| event | 只读 | string | 是 | 表示当前接收的公共事件名称。 |
| bundleName | 只读 | string | 否 | 表示包名称。 |
| code | 只读 | number | 否 | 表示公共事件的结果代码,用于传递int类型的数据。 |
| data | 只读 | string | 否 | 表示公共事件的自定义结果数据,用于传递string类型的数据。 |
| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息。 |
\ No newline at end of file
# 公共事件内容和属性
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## CommonEventPublishData
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Notification.CommonEvent
| 名称 | 读写属性 | 类型 | 必填 | 描述 |
| --------------------- | -------- | -------------------- | ---- | ---------------------------- |
| bundleName | 只读 | string | 否 | 表示包名称。 |
| code | 只读 | number | 否 | 表示公共事件的结果代码。 |
| data | 只读 | string | 否 | 表示公共事件的自定义结果数据。 |
| subscriberPermissions | 只读 | Array\<string> | 否 | 表示订阅者的权限。 |
| isOrdered | 只读 | boolean | 否 | 表示是否是有序事件。 |
| isSticky | 只读 | boolean | 否 | 表示是否是粘性事件。 |
| parameters | 只读 | {[key: string]: any} | 否 | 表示公共事件的附加信息。 |
# 订阅者的信息
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 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
# 公共事件的订阅者
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## CommonEventSubscriber
### getCode
getCode(callback: AsyncCallback\<number>): void
获取公共事件的结果代码(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ---------------------- | ---- | ------------------ |
| callback | AsyncCallback\<number> | 是 | 公共事件的结果代码。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getCodeCallback(err, Code) {
if (err.code) {
console.error("getCode failed " + JSON.stringify(err));
} else {
console.info("getCode " + JSON.stringify(Code));
}
}
subscriber.getCode(getCodeCallback);
```
### getCode
getCode(): Promise\<number>
获取公共事件的结果代码(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<number> | 公共事件的结果代码。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getCode().then((Code) => {
console.info("getCode " + JSON.stringify(Code));
}).catch((err) => {
console.error("getCode failed " + JSON.stringify(err));
});
```
### setCode
setCode(code: number, callback: AsyncCallback\<void>): void
设置公共事件的结果代码(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | 是 | 公共事件的结果代码。 |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function setCodeCallback(err) {
if (err.code) {
console.error("setCode failed " + JSON.stringify(err));
} else {
console.info("setCode");
}
}
subscriber.setCode(1, setCodeCallback);
```
### setCode
setCode(code: number): Promise\<void>
设置公共事件的结果代码(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| ------ | ------ | ---- | ------------------ |
| code | number | 是 | 公共事件的结果代码。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.setCode(1).then(() => {
console.info("setCode");
}).catch((err) => {
console.error("setCode failed " + JSON.stringify(err));
});
```
### getData
getData(callback: AsyncCallback\<string>): void
获取公共事件的结果数据(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ---------------------- | ---- | -------------------- |
| callback | AsyncCallback\<string> | 是 | 公共事件的结果数据。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getDataCallback(err, Data) {
if (err.code) {
console.error("getData failed " + JSON.stringify(err));
} else {
console.info("getData " + JSON.stringify(Data));
}
}
subscriber.getData(getDataCallback);
```
### getData
getData(): Promise\<string>
获取公共事件的结果数据(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ---------------- | ------------------ |
| Promise\<string> | 公共事件的结果数据。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getData().then((Data) => {
console.info("getData " + JSON.stringify(Data));
}).catch((err) => {
console.error("getData failed " + JSON.stringify(err));
});
```
### setData
setData(data: string, callback: AsyncCallback\<void>): void
设置公共事件的结果数据(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------- |
| data | string | 是 | 公共事件的结果数据。 |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function setDataCallback(err) {
if (err.code) {
console.error("setData failed " + JSON.stringify(err));
} else {
console.info("setData");
}
}
subscriber.setData("publish_data_changed", setDataCallback);
```
### setData
setData(data: string): Promise\<void>
设置公共事件的结果数据(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| ------ | ------ | ---- | -------------------- |
| data | string | 是 | 公共事件的结果数据。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.setData("publish_data_changed").then(() => {
console.info("setData");
}).catch((err) => {
console.error("setData failed " + JSON.stringify(err));
});
```
### setCodeAndData
setCodeAndData(code: number, data: string, callback:AsyncCallback\<void>): void
设置公共事件的结果代码和结果数据(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | ---------------------- |
| code | number | 是 | 公共事件的结果代码。 |
| data | string | 是 | 公共事件的结果数据。 |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function setCodeDataCallback(err) {
if (err.code) {
console.error("setCodeAndData failed " + JSON.stringify(err));
} else {
console.info("setCodeDataCallback");
}
}
subscriber.setCodeAndData(1, "publish_data_changed", setCodeDataCallback);
```
### setCodeAndData
setCodeAndData(code: number, data: string): Promise\<void>
设置公共事件的结果代码和结果数据(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| ------ | ------ | ---- | -------------------- |
| code | number | 是 | 公共事件的结果代码。 |
| data | string | 是 | 公共事件的结果数据。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.setCodeAndData(1, "publish_data_changed").then(() => {
console.info("setCodeAndData");
}).catch((err) => {
console.info("setCodeAndData failed " + JSON.stringify(err));
});
```
### isOrderedCommonEvent
isOrderedCommonEvent(callback: AsyncCallback\<boolean>): void
查询当前公共事件的是否为有序公共事件(callback形式)。
返回true代表是有序公共事件,false代表不是有序公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 当前公共事件的是否为有序公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function isOrderedCallback(err, isOrdered) {
if (err.code) {
console.error("isOrderedCommonEvent failed " + JSON.stringify(err));
} else {
console.info("isOrdered " + JSON.stringify(isOrdered));
}
}
subscriber.isOrderedCommonEvent(isOrderedCallback);
```
### isOrderedCommonEvent
isOrderedCommonEvent(): Promise\<boolean>
查询当前公共事件的是否为有序公共事件(Promise形式)。
返回true代表是有序公共事件,false代表不是有序公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ----------------- | -------------------------------- |
| Promise\<boolean> | 当前公共事件的是否为有序公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.isOrderedCommonEvent().then((isOrdered) => {
console.info("isOrdered " + JSON.stringify(isOrdered));
}).catch((err) => {
console.error("isOrdered failed " + JSON.stringify(err));
});
```
### isStickyCommonEvent
isStickyCommonEvent(callback: AsyncCallback\<boolean>): void
检查当前公共事件是否为一个粘性事件(callback形式)。
返回true代表是粘性公共事件,false代表不是粘性公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 当前公共事件的是否为粘性公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function isStickyCallback(err, isSticky) {
if (err.code) {
console.error("isStickyCommonEvent failed " + JSON.stringify(err));
} else {
console.info("isSticky " + JSON.stringify(isSticky));
}
}
subscriber.isStickyCommonEvent(isStickyCallback);
```
### isStickyCommonEvent
isStickyCommonEvent(): Promise\<boolean>
检查当前公共事件是否为一个粘性事件(callback形式)。
返回true代表是粘性公共事件,false代表不是粘性公共事件。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ----------------- | -------------------------------- |
| Promise\<boolean> | 当前公共事件的是否为粘性公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.isStickyCommonEvent().then((isSticky) => {
console.info("isSticky " + JSON.stringify(isSticky));
}).catch((err) => {
console.error("isSticky failed " + JSON.stringify(err));
});
```
### abortCommonEvent
abortCommonEvent(callback: AsyncCallback\<void>): void
取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | 是 | 取消当前的公共事件。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function abortCallback(err) {
if (err.code) {
console.error("abortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("abortCommonEvent");
}
}
subscriber.abortCommonEvent(abortCallback);
```
### abortCommonEvent
abortCommonEvent(): Promise\<void>
取消当前的公共事件,仅对有序公共事件有效,取消后,公共事件不再向下一个订阅者传递(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.abortCommonEvent().then(() => {
console.info("abortCommonEvent");
}).catch((err) => {
console.error("abortCommonEvent failed " + JSON.stringify(err));
});
```
### clearAbortCommonEvent
clearAbortCommonEvent(callback: AsyncCallback\<void>): void
清除当前公共事件的取消状态,仅对有序公共事件有效(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------- |
| callback | AsyncCallback\<void> | 是 | 表示被指定的回调方法。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function clearAbortCallback(err) {
if (err.code) {
console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("clearAbortCommonEvent");
}
}
subscriber.clearAbortCommonEvent(clearAbortCallback);
```
### clearAbortCommonEvent
clearAbortCommonEvent(): Promise\<void>
清除当前公共事件的取消状态,仅对有序公共事件有效(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.clearAbortCommonEvent().then(() => {
console.info("clearAbortCommonEvent");
}).catch((err) => {
console.error("clearAbortCommonEvent failed " + JSON.stringify(err));
});
```
### getAbortCommonEvent
getAbortCommonEvent(callback: AsyncCallback\<boolean>): void
获取当前有序公共事件是否取消的状态(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ----------------------- | ---- | ---------------------------------- |
| callback | AsyncCallback\<boolean> | 是 | 表示当前有序公共事件是否取消的状态。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getAbortCallback(err, AbortCommonEvent) {
if (err.code) {
console.error("getAbortCommonEvent failed " + JSON.stringify(err));
} else {
console.info("AbortCommonEvent " + AbortCommonEvent)
}
}
subscriber.getAbortCommonEvent(getAbortCallback);
```
### getAbortCommonEvent
getAbortCommonEvent(): Promise\<boolean>
获取当前有序公共事件是否取消的状态(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ----------------- | ---------------------------------- |
| Promise\<boolean> | 表示当前有序公共事件是否取消的状态。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getAbortCommonEvent().then((AbortCommonEvent) => {
console.info("AbortCommonEvent " + JSON.stringify(AbortCommonEvent));
}).catch((err) => {
console.error("getAbortCommonEvent failed " + JSON.stringify(err));
});
```
### getSubscribeInfo
getSubscribeInfo(callback: AsyncCallback\<CommonEventSubscribeInfo>): void
获取订阅者的订阅信息(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | ------------------------------------------------------------ | ---- | ---------------------- |
| callback | AsyncCallback\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 是 | 表示订阅者的订阅信息。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
//设置有序公共事件的结果数据回调
function getSubscribeInfoCallback(err, SubscribeInfo) {
if (err.code) {
console.error("getSubscribeInfo failed " + JSON.stringify(err));
} else {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}
}
subscriber.getSubscribeInfo(getSubscribeInfoCallback);
```
### getSubscribeInfo
getSubscribeInfo(): Promise\<CommonEventSubscribeInfo>
获取订阅者的订阅信息(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**返回值:**
| 类型 | 说明 |
| ------------------------------------------------------------ | ---------------------- |
| Promise\<[CommonEventSubscribeInfo](#commoneventsubscribeinfo)> | 表示订阅者的订阅信息。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.getSubscribeInfo().then((SubscribeInfo) => {
console.info("SubscribeInfo " + JSON.stringify(SubscribeInfo));
}).catch((err) => {
console.error("getSubscribeInfo failed " + JSON.stringify(err));
});
```
### finishCommonEvent
finishCommonEvent(callback: AsyncCallback\<void\>): void
结束当前已排序的公共事件(callback形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**参数:**
| 参数名 | 类型 | 必填 | 描述 |
| -------- | -------------------- | ---- | -------------------------------- |
| callback | AsyncCallback\<void> | 是 | 表示排序的公共事件结束后的回调函数。 |
**示例:**
```js
var subscriber; //创建成功的订阅者对象
function finishCommonEventCallback() {
console.log("--------- finishCommonEventCallback ----------");
}
subscriber.finishCommonEvent(finishCommonEventCallback);
```
### finishCommonEvent
finishCommonEvent(): Promise\<void\>
结束当前已排序的公共事件(Promise形式)。
**系统能力**:SystemCapability.Notification.CommonEvent
**示例:**
```js
var subscriber; //创建成功的订阅者对象
subscriber.finishCommonEvent()
.then(() => {
console.info("--------- finishCommonEventCallback ----------");
})
```
\ No newline at end of file
# Notification模块 # Notification模块
>**说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
...@@ -292,7 +291,7 @@ addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void ...@@ -292,7 +291,7 @@ addSlot(slot: NotificationSlot, callback: AsyncCallback\<void\>): void
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------- | ---- | -------------------- | | -------- | ---- | --- | --------------------- | ---- | -------------------- |
| slot | 是 | 否 | NotificationSlot | 是 | 要创建的通知通道对象。 | | slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 要创建的通知通道对象。 |
| callback | 是 | 否 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法。 | | callback | 是 | 否 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法。 |
**示例:** **示例:**
...@@ -323,7 +322,7 @@ addSlot(slot: NotificationSlot): Promise\<void\> ...@@ -323,7 +322,7 @@ addSlot(slot: NotificationSlot): Promise\<void\>
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ---- | ---- | --- | ---------------- | ---- | -------------------- | | ---- | ---- | --- | ---------------- | ---- | -------------------- |
| slot | 是 | 否 | NotificationSlot | 是 | 要创建的通知通道对象。 | | slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 要创建的通知通道对象。 |
**示例:** **示例:**
...@@ -402,7 +401,7 @@ addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): voi ...@@ -402,7 +401,7 @@ addSlots(slots: Array\<NotificationSlot\>, callback: AsyncCallback\<void\>): voi
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | ------------------------- | ---- | ------------------------ | | -------- | ---- | --- | ------------------------- | ---- | ------------------------ |
| slots | 是 | 否 | Array\<NotificationSlot\> | 是 | 要创建的通知通道对象数组。 | | slots | 是 | 否 | Array\<[NotificationSlot](#notificationslot)\> | 是 | 要创建的通知通道对象数组。 |
| callback | 是 | 否 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法。 | | callback | 是 | 否 | AsyncCallback\<void\> | 是 | 表示被指定的回调方法。 |
**示例:** **示例:**
...@@ -437,7 +436,7 @@ addSlots(slots: Array\<NotificationSlot\>): Promise\<void\> ...@@ -437,7 +436,7 @@ addSlots(slots: Array\<NotificationSlot\>): Promise\<void\>
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ----- | ---- | --- | ------------------------- | ---- | ------------------------ | | ----- | ---- | --- | ------------------------- | ---- | ------------------------ |
| slots | 是 | 否 | Array\<NotificationSlot\> | 是 | 要创建的通知通道对象数组。 | | slots | 是 | 否 | Array\<[NotificationSlot](#notificationslot)\> | 是 | 要创建的通知通道对象数组。 |
**示例:** **示例:**
...@@ -470,7 +469,7 @@ getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void ...@@ -470,7 +469,7 @@ getSlot(slotType: SlotType, callback: AsyncCallback\<NotificationSlot\>): void
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------------------- | ---- | ----------------------------------------------------------- | | -------- | ---- | --- | --------------------------------- | ---- | ----------------------------------------------------------- |
| slotType | 是 | 否 | [SlotType](#slottype) | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 | | slotType | 是 | 否 | [SlotType](#slottype) | 是 | 通知渠道类型,目前分为社交通信、服务提醒、内容咨询和其他类型。 |
| callback | 是 | 否 | AsyncCallback\<NotificationSlot\> | 是 | 表示被指定的回调方法。 | | callback | 是 | 否 | AsyncCallback\<[NotificationSlot](#notificationslot)\> | 是 | 表示被指定的回调方法。 |
**示例:** **示例:**
...@@ -528,7 +527,7 @@ getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>): void ...@@ -528,7 +527,7 @@ getSlots(callback: AsyncCallback<Array\<NotificationSlot\>>): void
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------------------- | ---- | -------------------- | | -------- | ---- | --- | --------------------------------- | ---- | -------------------- |
| callback | 是 | 否 | AsyncCallback\<NotificationSlot\> | 是 | 表示被指定的回调方法。 | | callback | 是 | 否 | AsyncCallback\<[NotificationSlot](#notificationslot)\> | 是 | 表示被指定的回调方法。 |
**示例:** **示例:**
...@@ -554,7 +553,7 @@ getSlots(): Promise\<Array\<NotificationSlot\>> ...@@ -554,7 +553,7 @@ getSlots(): Promise\<Array\<NotificationSlot\>>
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<Array\<NotificationSlot\>\> | 以Promise形式返回获取此应用程序的所有通知通道的结果。 | | Promise\<Array\<[NotificationSlot](#notificationslot)\>\> | 以Promise形式返回获取此应用程序的所有通知通道的结果。 |
**示例:** **示例:**
...@@ -1133,7 +1132,7 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCal ...@@ -1133,7 +1132,7 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot, callback: AsyncCal
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------- | ---- | -------------------- | | -------- | ---- | --- | --------------------- | ---- | -------------------- |
| bundle | 是 | 否 | [BundleOption](#bundleoption) | 是 | 指定包信息。 | | bundle | 是 | 否 | [BundleOption](#bundleoption) | 是 | 指定包信息。 |
| slot | 是 | 否 | NotificationSlot | 是 | 通知通道。 | | slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 通知通道。 |
| callback | 是 | 否 | AsyncCallback\<void\> | 是 | 设定通知通道回调函数。 | | callback | 是 | 否 | AsyncCallback\<void\> | 是 | 设定通知通道回调函数。 |
**示例:** **示例:**
...@@ -1166,7 +1165,7 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\> ...@@ -1166,7 +1165,7 @@ setSlotByBundle(bundle: BundleOption, slot: NotificationSlot): Promise\<void\>
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ------ | ---- | --- | ------------ | ---- | ---------- | | ------ | ---- | --- | ------------ | ---- | ---------- |
| bundle | 是 | 否 | [BundleOption](#bundleoption) | 是 | 指定包信息。 | | bundle | 是 | 否 | [BundleOption](#bundleoption) | 是 | 指定包信息。 |
| enable | 是 | 否 | boolean | 是 | 使能状态。 | | slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 使能状态。 |
**示例:** **示例:**
...@@ -1197,7 +1196,7 @@ getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<Notificati ...@@ -1197,7 +1196,7 @@ getSlotsByBundle(bundle: BundleOption, callback: AsyncCallback<Array\<Notificati
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | ---------------------------------------- | ---- | -------------------- | | -------- | ---- | --- | ---------------------------------------- | ---- | -------------------- |
| bundle | 是 | 否 | [BundleOption](#bundleoption) | 是 | 指定包信息。 | | bundle | 是 | 否 | [BundleOption](#bundleoption) | 是 | 指定包信息。 |
| callback | 是 | 否 | AsyncCallback<Array\<NotificationSlot\>> | 是 | 获取通知通道回调函数。 | | callback | 是 | 否 | AsyncCallback<Array\<[NotificationSlot](#notificationslot)\>> | 是 | 获取通知通道回调函数。 |
**示例:** **示例:**
...@@ -1231,7 +1230,7 @@ getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>> ...@@ -1231,7 +1230,7 @@ getSlotsByBundle(bundle: BundleOption): Promise<Array\<NotificationSlot\>>
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise<Array\<NotificationSlot\>> | 以Promise形式返回获取指定包的通知通道。 | | Promise<Array\<[NotificationSlot](#notificationslot)\>> | 以Promise形式返回获取指定包的通知通道。 |
**示例:** **示例:**
...@@ -1830,7 +1829,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): vo ...@@ -1830,7 +1829,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate, callback: AsyncCallback\<void\>): vo
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------- | ---- | ---------------------- | | -------- | ---- | --- | --------------------- | ---- | ---------------------- |
| date | 是 | 否 | DoNotDisturbDate | 是 | 免打扰时间选项。 | | date | 是 | 否 | [DoNotDisturbDate](#donotdisturbdate8) | 是 | 免打扰时间选项。 |
| callback | 是 | 否 | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数。 | | callback | 是 | 否 | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数。 |
**示例:** **示例:**
...@@ -1863,7 +1862,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\> ...@@ -1863,7 +1862,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate): Promise\<void\>
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ---- | ---- | --- | ---------------- | ---- | -------------- | | ---- | ---- | --- | ---------------- | ---- | -------------- |
| date | 是 | 否 | DoNotDisturbDate | 是 | 免打扰时间选项。 | | date | 是 | 否 | [DoNotDisturbDate](#donotdisturbdate8) | 是 | 免打扰时间选项。 |
**示例:** **示例:**
...@@ -1891,7 +1890,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallb ...@@ -1891,7 +1890,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number, callback: AsyncCallb
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------- | ---- | ---------------------- | | -------- | ---- | --- | --------------------- | ---- | ---------------------- |
| date | 是 | 否 | DoNotDisturbDate | 是 | 免打扰时间选项。 | | date | 是 | 否 | [DoNotDisturbDate](#donotdisturbdate8) | 是 | 免打扰时间选项。 |
| userId | 是 | 否 | number | 是 | 设置免打扰事件的用户ID。 | | userId | 是 | 否 | number | 是 | 设置免打扰事件的用户ID。 |
| callback | 是 | 否 | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数。 | | callback | 是 | 否 | AsyncCallback\<void\> | 是 | 设置免打扰时间回调函数。 |
...@@ -1927,7 +1926,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\> ...@@ -1927,7 +1926,7 @@ setDoNotDisturbDate(date: DoNotDisturbDate, userId: number): Promise\<void\>
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ------ | ---- | --- | ---------------- | ---- | -------------- | | ------ | ---- | --- | ---------------- | ---- | -------------- |
| date | 是 | 否 | DoNotDisturbDate | 是 | 免打扰时间选项。 | | date | 是 | 否 | [DoNotDisturbDate](#donotdisturbdate8) | 是 | 免打扰时间选项。 |
| userId | 是 | 否 | number | 是 | 设置免打扰事件的用户ID。 | | userId | 是 | 否 | number | 是 | 设置免打扰事件的用户ID。 |
**示例:** **示例:**
...@@ -1959,7 +1958,7 @@ getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void ...@@ -1959,7 +1958,7 @@ getDoNotDisturbDate(callback: AsyncCallback\<DoNotDisturbDate\>): void
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- | | -------- | ---- | --- | --------------------------------- | ---- | ---------------------- |
| callback | 是 | 否 | AsyncCallback\<DoNotDisturbDate\> | 是 | 查询免打扰时间回调函数。 | | callback | 是 | 否 | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8)\> | 是 | 查询免打扰时间回调函数。 |
**示例:** **示例:**
...@@ -1985,7 +1984,7 @@ getDoNotDisturbDate(): Promise\<DoNotDisturbDate\> ...@@ -1985,7 +1984,7 @@ getDoNotDisturbDate(): Promise\<DoNotDisturbDate\>
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<DoNotDisturbDate\> | 以Promise形式返回获取查询免打扰时间接口。 | | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | 以Promise形式返回获取查询免打扰时间接口。 |
**示例:** **示例:**
...@@ -2008,7 +2007,7 @@ getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>) ...@@ -2008,7 +2007,7 @@ getDoNotDisturbDate(userId: number, callback: AsyncCallback\<DoNotDisturbDate\>)
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 | | 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | --------------------------------- | ---- | ---------------------- | | -------- | ---- | --- | --------------------------------- | ---- | ---------------------- |
| callback | 是 | 否 | AsyncCallback\<DoNotDisturbDate\> | 是 | 查询免打扰时间回调函数。 | | callback | 是 | 否 | AsyncCallback\<[DoNotDisturbDate](#donotdisturbdate8)\> | 是 | 查询免打扰时间回调函数。 |
| userId | 是 | 否 | number | 是 | 设置免打扰事件的用户ID。 | | userId | 是 | 否 | number | 是 | 设置免打扰事件的用户ID。 |
**示例:** **示例:**
...@@ -2043,7 +2042,7 @@ getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\> ...@@ -2043,7 +2042,7 @@ getDoNotDisturbDate(userId: number): Promise\<DoNotDisturbDate\>
| 类型 | 说明 | | 类型 | 说明 |
| ----------------------------------------------------------- | ------------------------------------------------------------ | | ----------------------------------------------------------- | ------------------------------------------------------------ |
| Promise\<DoNotDisturbDate\> | 以Promise形式返回获取查询免打扰时间接口。 | | Promise\<[DoNotDisturbDate](#donotdisturbdate8)\> | 以Promise形式返回获取查询免打扰时间接口。 |
**示例:** **示例:**
...@@ -2327,7 +2326,7 @@ enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: Async ...@@ -2327,7 +2326,7 @@ enableDistributedByBundle(bundle: BundleOption, enable: boolean, callback: Async
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| bundle | BundleOption | 是 | 应用的包。 | | bundle | [BundleOption](#bundleoption) | 是 | 应用的包。 |
| enable | boolean | 是 | 是否支持。 | | enable | boolean | 是 | 是否支持。 |
| callback | AsyncCallback\<void\> | 是 | 应用程序是否支持分布式通知的回调函数。 | | callback | AsyncCallback\<void\> | 是 | 应用程序是否支持分布式通知的回调函数。 |
...@@ -2361,7 +2360,7 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle ...@@ -2361,7 +2360,7 @@ Notification.enableDistributedByBundle(bundle, enable, enableDistributedByBundle
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| bundle | BundleOption | 是 | 应用的包。 | | bundle | [BundleOption](#bundleoption) | 是 | 应用的包。 |
| enable | boolean | 是 | 是否支持。 | | enable | boolean | 是 | 是否支持。 |
**示例:** **示例:**
...@@ -2391,7 +2390,7 @@ isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<bool ...@@ -2391,7 +2390,7 @@ isDistributedEnabledByBundle(bundle: BundleOption, callback: AsyncCallback\<bool
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| bundle | BundleOption | 是 | 应用的包。 | | bundle | [BundleOption](#bundleoption) | 是 | 应用的包。 |
| callback | AsyncCallback\<boolean\> | 是 | 应用程序是否支持分布式通知的回调函数。 | | callback | AsyncCallback\<boolean\> | 是 | 应用程序是否支持分布式通知的回调函数。 |
**示例:** **示例:**
...@@ -2422,7 +2421,7 @@ isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean> ...@@ -2422,7 +2421,7 @@ isDistributedEnabledByBundle(bundle: BundleOption): Promise\<boolean>
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------ | ---- | -------------------------- | | -------- | ------------------------ | ---- | -------------------------- |
| bundle | BundleOption | 是 | 应用的包。 | | bundle | [BundleOption](#bundleoption) | 是 | 应用的包。 |
**返回值:** **返回值:**
...@@ -2456,7 +2455,7 @@ getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void ...@@ -2456,7 +2455,7 @@ getDeviceRemindType(callback: AsyncCallback\<DeviceRemindType\>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------- | ---- | -------------------------- | | -------- | --------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<DeviceRemindType\> | 是 | 获取通知的提醒方式的回调函数。 | | callback | AsyncCallback\<[DeviceRemindType](#deviceremindtypesup8sup)\> | 是 | 获取通知的提醒方式的回调函数。 |
**示例:** **示例:**
...@@ -2482,7 +2481,7 @@ getDeviceRemindType(): Promise\<DeviceRemindType\> ...@@ -2482,7 +2481,7 @@ getDeviceRemindType(): Promise\<DeviceRemindType\>
| 类型 | 说明 | | 类型 | 说明 |
| ------------------ | --------------- | | ------------------ | --------------- |
| Promise\<DeviceRemindType\> | Promise方式返回通知的提醒方式的结果。 | | Promise\<[DeviceRemindType](#deviceremindtypesup8sup)\> | Promise方式返回通知的提醒方式的结果。 |
**示例:** **示例:**
...@@ -2493,6 +2492,320 @@ Notification.getDeviceRemindType() ...@@ -2493,6 +2492,320 @@ Notification.getDeviceRemindType()
}); });
``` ```
## NotificationSubscriber
### onConsume
onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata))
接收通知回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onConsumeCallback(data) {
console.info('===> onConsume in test');
let req = data.request;
console.info('===> onConsume callback req.id:' + req.id);
let wantAgent = data.wantAgent;
wantAgent .getWant(wantAgent)
.then((data1) => {
console.log('===> getWant success want:' + JSON.stringfy(data1));
})
.catch((err) => {
console.error('===> getWant failed because' + JSON.stringfy(err));
});
console.info('===> onConsume callback req.wantAgent:' + JSON.stringfy(req.wantAgent));
};
var subscriber = {
onConsume: onConsumeCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onCancel
onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata))
删除通知回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onCancelCallback(data) {
console.info('===> onCancel in test');
let req = data.request;
console.info('===> onCancel callback req.id:' + req.id);
}
var subscriber = {
onCancel: onCancelCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onUpdate
onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap))
更新通知排序回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data | [NotificationSortingMap](#notificationsortingmap) | 是 | 回调返回接收到的通知信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onUpdateCallback() {
console.info('===> onUpdate in test');
}
var subscriber = {
onUpdate: onUpdateCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onConnect
onConnect?:void
注册订阅回调函数。
**系统能力**:SystemCapability.Notification.Notification
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onConnectCallback() {
console.info('===> onConnect in test');
}
var subscriber = {
onConnect: onConnectCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onDisconnect
onDisconnect?:void
取消订阅回调函数。
**系统能力**:SystemCapability.Notification.Notification
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDisconnectCallback() {
console.info('===> onDisconnect in test');
}
var subscriber = {
onDisconnect: onDisconnectCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onDestroy
onDestroy?:void
服务失联回调函数。
**系统能力**:SystemCapability.Notification.Notification
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDestroyCallback() {
console.info('===> onDestroy in test');
}
var subscriber = {
onDestroy: onDestroyCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onDoNotDisturbDateChange<sup>8+</sup>
onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate8))
免打扰时间选项变更回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| mode | Notification.[DoNotDisturbDate](#donotdisturbdate8) | 是 | 回调返回免打扰时间选项变更。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDoNotDisturbDateChangeCallback() {
console.info('===> onDoNotDisturbDateChange in test');
}
var subscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onEnabledNotificationChanged<sup>8+</sup>
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdatasup8sup))
监听应用通知使能变化。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdatasup8sup)\> | 是 | 回调返回监听到的应用信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onEnabledNotificationChangedCallback(err, callbackData) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("bundle: ", callbackData.bundle);
console.info("uid: ", callbackData.uid);
console.info("enable: ", callbackData.enable);
}
};
var subscriber = {
onEnabledNotificationChanged: onEnabledNotificationChangedCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
## SubscribeCallbackData
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| --------------- | ---- | --- | ------------------------------------------------- | ---- | -------- |
| request | 是 | 否 | [NotificationRequest](#notificationrequest) | 是 | 通知内容。 |
| sortingMap | 是 | 否 | [NotificationSortingMap](#notificationsortingmap) | 否 | 排序信息。 |
| reason | 是 | 否 | number | 否 | 删除原因。 |
| sound | 是 | 否 | string | 否 | 通知声音。 |
| vibrationValues | 是 | 否 | Array\<number\> | 否 | 通知震动。 |
## EnabledNotificationCallbackData<sup>8+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ------ | ---- | --- | ------- | ---- | ---------------- |
| bundle | 是 | 否 | string | 是 | 应用的包名。 |
| uid | 是 | 否 | number | 是 | 应用的uid。 |
| enable | 是 | 否 | boolean | 是 | 应用通知使能状态。 |
## DoNotDisturbDate<sup>8+</sup> ## DoNotDisturbDate<sup>8+</sup>
...@@ -2500,7 +2813,7 @@ Notification.getDeviceRemindType() ...@@ -2500,7 +2813,7 @@ Notification.getDeviceRemindType()
| 名称 | 可读 | 可写 | 类型 | 描述 | | 名称 | 可读 | 可写 | 类型 | 描述 |
| ----- | ---- | --- | ------------------------------------- | ------------------------ | | ----- | ---- | --- | ------------------------------------- | ------------------------ |
| type | 是 | 否 | [DoNotDisturbType](#donotdisturbtype) | 指定免打扰设置的时间类型。 | | type | 是 | 否 | [DoNotDisturbType](#donotdisturbtype8) | 指定免打扰设置的时间类型。 |
| begin | 是 | 否 | Date | 指定免打扰设置的起点时间。 | | begin | 是 | 否 | Date | 指定免打扰设置的起点时间。 |
| end | 是 | 否 | Date | 指定免打扰设置的终点时间。 | | end | 是 | 否 | Date | 指定免打扰设置的终点时间。 |
...@@ -2575,4 +2888,241 @@ Notification.getDeviceRemindType() ...@@ -2575,4 +2888,241 @@ Notification.getDeviceRemindType()
| SOCIAL_COMMUNICATION | SlotType | 社交类型。 | | SOCIAL_COMMUNICATION | SlotType | 社交类型。 |
| SERVICE_INFORMATION | SlotType | 服务类型。 | | SERVICE_INFORMATION | SlotType | 服务类型。 |
| CONTENT_INFORMATION | SlotType | 内容类型。 | | CONTENT_INFORMATION | SlotType | 内容类型。 |
| OTHER_TYPES | SlotType | 其他类型。 | | OTHER_TYPES | SlotType | 其他类型。 |
\ No newline at end of file
## NotificationActionButton
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| --------- | --- | ---- | ----------------------------------------------- | ---- | ------------------------- |
| title | 是 | 是 | string | 是 | 按钮标题。 |
| wantAgent | 是 | 是 | WantAgent | 是 | 点击按钮时触发的WantAgent。 |
| extras | 是 | 是 | { [key: string]: any } | 否 | 按钮扩展信息。 |
| userInput<sup>9+</sup> | 是 | 是 | [NotificationUserInput](#notificationuserinputsup8sup) | 否 | 用户输入对象实例。 |
## NotificationBasicContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | ---- | ------ | ---- | ---------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
## NotificationLongTextContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | --- | ------ | ---- | -------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
| longText | 是 | 是 | string | 是 | 通知的长文本。 |
| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 |
| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 |
## NotificationMultiLineContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | --- | --- | --------------- | ---- | -------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 |
| longTitle | 是 | 是 | string | 是 | 通知展开时的标题。 |
| lines | 是 | 是 | Array\<string\> | 是 | 通知的多行文本。 |
## NotificationPictureContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | --- | -------------- | ---- | -------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 |
| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 |
| picture | 是 | 是 | image.PixelMap | 是 | 通知的图片内容。 |
## NotificationContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ----------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------ |
| contentType | 是 | 是 | [ContentType](#contenttype) | 是 | 通知内容类型。 |
| normal | 是 | 是 | [NotificationBasicContent](#notificationbasiccontent) | 否 | 基本类型通知内容。 |
| longText | 是 | 是 | [NotificationLongTextContent](#notificationlongtextcontent) | 否 | 长文本类型通知内容。 |
| multiLine | 是 | 是 | [NotificationMultiLineContent](#notificationmultilinecontent) | 否 | 多行类型通知内容。 |
| picture | 是 | 是 | [NotificationPictureContent](#notificationpicturecontent) | 否 | 图片类型通知内容。 |
## NotificationFlagStatus<sup>8+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 值 | 描述 |
| -------------- | --- | --------------------------------- |
| TYPE_NONE | 0 | 默认标志。 |
| TYPE_OPEN | 1 | 通知标志打开。 |
| TYPE_CLOSE | 2 | 通知标志关闭。 |
## NotificationFlags<sup>8+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ---------------- | ---- | ---- | ---------------------- | ---- | --------------------------------- |
| soundEnabled | 是 | 否 | NotificationFlagStatus | 否 | 是否启用声音提示。 |
| vibrationEnabled | 是 | 否 | NotificationFlagStatus | 否 | 是否启用振动提醒功能。 |
## NotificationRequest
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| --------------------- | ---- | --- | --------------------------------------------- | ---- | -------------------------- |
| content | 是 | 是 | [NotificationContent](#notificationcontent) | 是 | 通知内容。 |
| id | 是 | 是 | number | 否 | 通知ID。 |
| slotType | 是 | 是 | [SlotType](#slottype) | 否 | 通道类型。 |
| isOngoing | 是 | 是 | boolean | 否 | 是否进行时通知。 |
| isUnremovable | 是 | 是 | boolean | 否 | 是否可移除。 |
| deliveryTime | 是 | 是 | number | 否 | 通知发送时间。 |
| tapDismissed | 是 | 是 | boolean | 否 | 通知是否自动清除。 |
| autoDeletedTime | 是 | 是 | number | 否 | 自动清除的时间。 |
| wantAgent | 是 | 是 | WantAgent | 否 | 点击跳转的WantAgent。 |
| extraInfo | 是 | 是 | {[key: string]: any} | 否 | 扩展参数。 |
| color | 是 | 是 | number | 否 | 通知背景颜色。 |
| colorEnabled | 是 | 是 | boolean | 否 | 通知背景颜色是否使能。 |
| isAlertOnce | 是 | 是 | boolean | 否 | 设置是否仅有一次此通知警报。 |
| isStopwatch | 是 | 是 | boolean | 否 | 是否显示已用时间。 |
| isCountDown | 是 | 是 | boolean | 否 | 是否显示倒计时时间。 |
| isFloatingIcon | 是 | 是 | boolean | 否 | 是否显示状态栏图标。 |
| label | 是 | 是 | string | 否 | 通知标签。 |
| badgeIconStyle | 是 | 是 | number | 否 | 通知角标类型。 |
| showDeliveryTime | 是 | 是 | boolean | 否 | 是否显示分发时间。 |
| actionButtons | 是 | 是 | Array\<[NotificationActionButton](#notificationactionbutton)\> | 否 | 通知按钮,最多两个按钮。 |
| smallIcon | 是 | 是 | PixelMap | 否 | 通知小图标。 |
| largeIcon | 是 | 是 | PixelMap | 否 | 通知大图标。 |
| creatorBundleName | 是 | 否 | string | 否 | 创建通知的包名。 |
| creatorUid | 是 | 否 | number | 否 | 创建通知的UID。 |
| creatorPid | 是 | 否 | number | 否 | 创建通知的PID。 |
| creatorUserId<sup>8+</sup>| 是 | 否 | number | 否 | 创建通知的UserId。 |
| hashCode | 是 | 否 | string | 否 | 通知唯一标识。 |
| classification | 是 | 是 | string | 否 | 通知分类。 |
| groupName<sup>8+</sup>| 是 | 是 | string | 否 | 组通知名称。 |
| template<sup>8+</sup> | 是 | 是 | [NotificationTemplate](#notificationtemplatesup8sup) | 否 | 通知模板。 |
| isRemoveAllowed<sup>8+</sup> | 是 | 否 | boolean | 否 | 通知是否能被移除。 |
| source<sup>8+</sup> | 是 | 否 | number | 否 | 通知源。 |
| distributedOption<sup>8+</sup> | 是 | 是 | [DistributedOptions](#distributedoptionssup8sup) | 否 | 分布式通知的选项。 |
| deviceId<sup>8+</sup> | 是 | 否 | string | 否 | 通知源的deviceId。 |
| notificationFlags<sup>8+</sup> | 是 | 否 | [NotificationFlags](#notificationflagssup8sup) | 否 | 获取NotificationFlags。 |
## DistributedOptions<sup>8+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ---------------------- | ---- | ---- | -------------- | ---- | ---------------------------------- |
| isDistributed | 是 | 是 | boolean | 否 | 是否为分布式通知。 |
| supportDisplayDevices | 是 | 是 | Array\<string> | 是 | 可以同步通知到的设备类型。 |
| supportOperateDevices | 是 | 是 | Array\<string> | 否 | 可以打开通知的设备。 |
| remindType | 是 | 否 | number | 否 | 通知的提醒方式。 |
## NotificationSlot
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------------- | ---- | --- | --------------------- | ---- | ------------------------------------------ |
| type | 是 | 是 | [SlotType](#slottype) | 是 | 通道类型。 |
| level | 是 | 是 | number | 否 | 通知级别,不设置则根据通知渠道类型有默认值。 |
| desc | 是 | 是 | string | 否 | 通知渠道描述信息。 |
| badgeFlag | 是 | 是 | boolean | 否 | 是否显示角标。 |
| bypassDnd | 是 | 是 | boolean | 否 | 置是否在系统中绕过免打扰模式。 |
| lockscreenVisibility | 是 | 是 | boolean | 否 | 在锁定屏幕上显示通知的模式。 |
| vibrationEnabled | 是 | 是 | boolean | 否 | 是否可振动。 |
| sound | 是 | 是 | string | 否 | 通知提示音。 |
| lightEnabled | 是 | 是 | boolean | 否 | 是否闪灯。 |
| lightColor | 是 | 是 | number | 否 | 通知灯颜色。 |
| vibrationValues | 是 | 是 | Array\<number\> | 否 | 通知振动样式。 |
## NotificationSorting
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | ------------------------------------- | ---- | ------------ |
| slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 通知通道内容。 |
| hashCode | 是 | 否 | string | 是 | 通知唯一标识。 |
| ranking | 是 | 否 | number | 是 | 通知排序序号。 |
## NotificationSortingMap
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | --- | ------------------------------------------------------------ | ---- | ---------------- |
| sortings | 是 | 否 | {[key: string]: [NotificationSorting](#notificationsorting)} | 是 | 通知排序信息数组。 |
| sortedHashCode | 是 | 否 | Array\<string\> | 是 | 通知唯一标识数组。 |
## NotificationSubscribeInfo
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ----------- | --- | ---- | --------------- | ---- | ------------------------------- |
| bundleNames | 是 | 是 | Array\<string\> | 否 | 指定订阅哪些包名的APP发来的通知。 |
| userId | 是 | 是 | number | 否 | 指定订阅哪个用户下发来的通知。 |
## NotificationTemplate<sup>8+</sup>
模板信息
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ---- | ---------------------- | ---- | ---- | ---------- |
| name | string | 是 | 是 | 模板名称。 |
| data | {[key:string]: Object} | 是 | 是 | 模板数据。 |
## NotificationUserInput<sup>8+</sup>
**系统能力**:SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | --- | ---- | ------ | ---- | ----------------------------- |
| inputKey | 是 | 是 | string | 是 | 用户输入时用于标识此输入的key。 |
## DeviceRemindType<sup>8+</sup>
**系统能力**:SystemCapability.Notification.Notification
| 名称 | 值 | 描述 |
| -------------------- | --- | --------------------------------- |
| IDLE_DONOT_REMIND | 0 | 设备未被使用,无需提醒。 |
| IDLE_REMIND | 1 | 提醒设备未被使用。 |
| ACTIVE_DONOT_REMIND | 2 | 设备正在使用,无需提醒。 |
| ACTIVE_REMIND | 3 | 提醒设备正在使用。 |
\ No newline at end of file
# 通知按钮
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
在通知中显示的操作按钮。
## NotificationActionButton
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| --------- | --- | ---- | ----------------------------------------------- | ---- | ------------------------- |
| title | 是 | 是 | string | 是 | 按钮标题。 |
| wantAgent | 是 | 是 | WantAgent | 是 | 点击按钮时触发的WantAgent。 |
| extras | 是 | 是 | { [key: string]: any } | 否 | 按钮扩展信息。 |
| userInput\<sup>9+</sup> | 是 | 是 | [NotificationUserInput](#notificationuserinput) | 否 | 用户输入对象实例。 |
\ No newline at end of file
# 通知内容
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
用于表示通知内容。
## NotificationBasicContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | ---- | ------ | ---- | ---------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
## NotificationLongTextContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | --- | ------ | ---- | -------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
| longText | 是 | 是 | string | 是 | 通知的长文本。 |
| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 |
| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 |
## NotificationMultiLineContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | --- | --- | --------------- | ---- | -------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 |
| longTitle | 是 | 是 | string | 是 | 通知展开时的标题。 |
| lines | 是 | 是 | Array\<string\> | 是 | 通知的多行文本。 |
## NotificationPictureContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | --- | -------------- | ---- | -------------------------------- |
| title | 是 | 是 | string | 是 | 通知标题。 |
| text | 是 | 是 | string | 是 | 通知内容。 |
| additionalText | 是 | 是 | string | 否 | 通知次要内容,是对通知内容的补充。 |
| briefText | 是 | 是 | string | 是 | 通知概要内容,是对通知内容的总结。 |
| expandedTitle | 是 | 是 | string | 是 | 通知展开时的标题。 |
| picture | 是 | 是 | image.PixelMap | 是 | 通知的图片内容。 |
## NotificationContent
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ----------- | ---- | --- | ------------------------------------------------------------ | ---- | ------------------ |
| contentType | 是 | 是 | [ContentType](#contenttype) | 是 | 通知内容类型。 |
| normal | 是 | 是 | [NotificationBasicContent](#notificationbasiccontent) | 否 | 基本类型通知内容。 |
| longText | 是 | 是 | [NotificationLongTextContent](#notificationlongtextcontent) | 否 | 长文本类型通知内容。 |
| multiLine | 是 | 是 | [NotificationMultiLineContent](#notificationmultilinecontent) | 否 | 多行类型通知内容。 |
| picture | 是 | 是 | [NotificationPictureContent](#notificationpicturecontent) | 否 | 图片类型通知内容。 |
\ No newline at end of file
# 通知标志
> **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## NotificationFlagStatus
通知标志的状态。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 值 | 描述 |
| -------------- | --- | --------------------------------- |
| TYPE_NONE | 0 | 默认标志。 |
| TYPE_OPEN | 1 | 通知标志打开。 |
| TYPE_CLOSE | 2 | 通知标志关闭。 |
## NotificationFlags
NotificationFlags实例。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ---------------- | ---- | ---- | ---------------------- | ---- | --------------------------------- |
| soundEnabled | 是 | 否 | NotificationFlagStatus | 否 | 是否启用声音提示。 |
| vibrationEnabled | 是 | 否 | NotificationFlagStatus | 否 | 是否启用振动提醒功能。 |
\ No newline at end of file
# NotificationRequest
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## NotificationRequest
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| --------------------- | ---- | --- | --------------------------------------------- | ---- | -------------------------- |
| content | 是 | 是 | [NotificationContent](#notificationcontent) | 是 | 通知内容。 |
| id | 是 | 是 | number | 否 | 通知ID。 |
| slotType | 是 | 是 | [SlotType](#slottype) | 否 | 通道类型。 |
| isOngoing | 是 | 是 | boolean | 否 | 是否进行时通知。 |
| isUnremovable | 是 | 是 | boolean | 否 | 是否可移除。 |
| deliveryTime | 是 | 是 | number | 否 | 通知发送时间。 |
| tapDismissed | 是 | 是 | boolean | 否 | 通知是否自动清除。 |
| autoDeletedTime | 是 | 是 | number | 否 | 自动清除的时间。 |
| wantAgent | 是 | 是 | WantAgent | 否 | 点击跳转的WantAgent。 |
| extraInfo | 是 | 是 | {[key: string]: any} | 否 | 扩展参数。 |
| color | 是 | 是 | number | 否 | 通知背景颜色。 |
| colorEnabled | 是 | 是 | boolean | 否 | 通知背景颜色是否使能。 |
| isAlertOnce | 是 | 是 | boolean | 否 | 设置是否仅有一次此通知警报。 |
| isStopwatch | 是 | 是 | boolean | 否 | 是否显示已用时间。 |
| isCountDown | 是 | 是 | boolean | 否 | 是否显示倒计时时间。 |
| isFloatingIcon | 是 | 是 | boolean | 否 | 是否显示状态栏图标。 |
| label | 是 | 是 | string | 否 | 通知标签。 |
| badgeIconStyle | 是 | 是 | number | 否 | 通知角标类型。 |
| showDeliveryTime | 是 | 是 | boolean | 否 | 是否显示分发时间。 |
| actionButtons | 是 | 是 | Array\<[NotificationActionButton](#notificationactionbutton)\> | 否 | 通知按钮,最多两个按钮。 |
| smallIcon | 是 | 是 | PixelMap | 否 | 通知小图标。 |
| largeIcon | 是 | 是 | PixelMap | 否 | 通知大图标。 |
| creatorBundleName | 是 | 否 | string | 否 | 创建通知的包名。 |
| creatorUid | 是 | 否 | number | 否 | 创建通知的UID。 |
| creatorPid | 是 | 否 | number | 否 | 创建通知的PID。 |
| creatorUserId<sup>8+</sup>| 是 | 否 | number | 否 | 创建通知的UserId。 |
| hashCode | 是 | 否 | string | 否 | 通知唯一标识。 |
| classification | 是 | 是 | string | 否 | 通知分类。 |
| groupName<sup>8+</sup>| 是 | 是 | string | 否 | 组通知名称。 |
| template<sup>8+</sup> | 是 | 是 | [NotificationTemplate](#notificationtemplate) | 否 | 通知模板。 |
| isRemoveAllowed<sup>8+</sup> | 是 | 否 | boolean | 否 | 通知是否能被移除。 |
| source<sup>8+</sup> | 是 | 否 | number | 否 | 通知源。 |
| distributedOption<sup>8+</sup> | 是 | 是 | DistributedOptions | 否 | 分布式通知的选项。 |
| deviceId<sup>8+</sup> | 是 | 否 | string | 否 | 通知源的deviceId。 |
| notificationFlags<sup>8+</sup> | 是 | 否 | NotificationFlags | 否 | 获取NotificationFlags。 |
## DistributedOptions<sup>8+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ---------------------- | ---- | ---- | -------------- | ---- | ---------------------------------- |
| isDistributed | 是 | 是 | boolean | 否 | 是否为分布式通知。 |
| supportDisplayDevices | 是 | 是 | Array\<string> | 是 | 可以同步通知到的设备类型。 |
| supportOperateDevices | 是 | 是 | Array\<string> | 否 | 可以打开通知的设备。 |
| remindType | 是 | 否 | number | 否 | 通知的提醒方式。 |
\ No newline at end of file
# NotificationSlot
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## NotificationSlot
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------------- | ---- | --- | --------------------- | ---- | ------------------------------------------ |
| type | 是 | 是 | [SlotType](#slottype) | 是 | 通道类型。 |
| level | 是 | 是 | number | 否 | 通知级别,不设置则根据通知渠道类型有默认值。 |
| desc | 是 | 是 | string | 否 | 通知渠道描述信息。 |
| badgeFlag | 是 | 是 | boolean | 否 | 是否显示角标。 |
| bypassDnd | 是 | 是 | boolean | 否 | 置是否在系统中绕过免打扰模式。 |
| lockscreenVisibility | 是 | 是 | boolean | 否 | 在锁定屏幕上显示通知的模式。 |
| vibrationEnabled | 是 | 是 | boolean | 否 | 是否可振动。 |
| sound | 是 | 是 | string | 否 | 通知提示音。 |
| lightEnabled | 是 | 是 | boolean | 否 | 是否闪灯。 |
| lightColor | 是 | 是 | number | 否 | 通知灯颜色。 |
| vibrationValues | 是 | 是 | Array\<number\> | 否 | 通知振动样式。 |
\ No newline at end of file
# 活跃通知排序
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
活跃通知的排序信息。
## NotificationSorting
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | ---- | --- | ------------------------------------- | ---- | ------------ |
| slot | 是 | 否 | [NotificationSlot](#notificationslot) | 是 | 通知通道内容。 |
| hashCode | 是 | 否 | string | 是 | 通知唯一标识。 |
| ranking | 是 | 否 | number | 是 | 通知排序序号。 |
\ No newline at end of file
# 通知排序
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
已订阅的所有通知中的活动通知的排序信息。
## NotificationSortingMap
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------------- | ---- | --- | ------------------------------------------------------------ | ---- | ---------------- |
| sortings | 是 | 否 | {[key: string]: [NotificationSorting](#notificationsorting)} | 是 | 通知排序信息数组。 |
| sortedHashCode | 是 | 否 | Array\<string\> | 是 | 通知唯一标识数组。 |
\ No newline at end of file
# 订阅通知的过滤条件
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
设置发布者订阅所需通知的过滤条件。
## NotificationSubscribeInfo
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ----------- | --- | ---- | --------------- | ---- | ------------------------------- |
| bundleNames | 是 | 是 | Array\<string\> | 否 | 指定订阅哪些包名的APP发来的通知。 |
| userId | 是 | 是 | number | 否 | 指定订阅哪个用户下发来的通知。 |
\ No newline at end of file
# 通知回调
> **说明:**
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
提供在订阅者收到新通知或取消通知时将回调的方法。
## NotificationSubscriber
### onConsume
onConsume?:(data: [SubscribeCallbackData](#subscribecallbackdata))
接收通知回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onConsumeCallback(data) {
console.info('===> onConsume in test');
let req = data.request;
console.info('===> onConsume callback req.id:' + req.id);
let wantAgent = data.wantAgent;
wantAgent .getWant(wantAgent)
.then((data1) => {
console.log('===> getWant success want:' + JSON.stringfy(data1));
})
.catch((err) => {
console.error('===> getWant failed because' + JSON.stringfy(err));
});
console.info('===> onConsume callback req.wantAgent:' + JSON.stringfy(req.wantAgent));
};
var subscriber = {
onConsume: onConsumeCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onCancel
onCancel?:(data: [SubscribeCallbackData](#subscribecallbackdata))
删除通知回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data | AsyncCallback\<[SubscribeCallbackData](#subscribecallbackdata)\> | 是 | 回调返回接收到的通知信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onCancelCallback(data) {
console.info('===> onCancel in test');
let req = data.request;
console.info('===> onCancel callback req.id:' + req.id);
}
var subscriber = {
onCancel: onCancelCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onUpdate
onUpdate?:(data: [NotificationSortingMap](#notificationsortingmap))
更新通知排序回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| data | [NotificationSortingMap](#notificationsortingmap) | 是 | 回调返回接收到的通知信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onUpdateCallback() {
console.info('===> onUpdate in test');
}
var subscriber = {
onUpdate: onUpdateCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onConnect
onConnect?:void
注册订阅回调函数。
**系统能力**:SystemCapability.Notification.Notification
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onConnectCallback() {
console.info('===> onConnect in test');
}
var subscriber = {
onConnect: onConnectCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onDisconnect
onDisconnect?:void
取消订阅回调函数。
**系统能力**:SystemCapability.Notification.Notification
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDisconnectCallback() {
console.info('===> onDisconnect in test');
}
var subscriber = {
onDisconnect: onDisconnectCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onDestroy
onDestroy?:void
服务失联回调函数。
**系统能力**:SystemCapability.Notification.Notification
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDestroyCallback() {
console.info('===> onDestroy in test');
}
var subscriber = {
onDestroy: onDestroyCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onDoNotDisturbDateChange<sup>8+</sup>
onDoNotDisturbDateChange?:(mode: Notification.[DoNotDisturbDate](#donotdisturbdate))
免打扰时间选项变更回调函数。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| mode | Notification.[DoNotDisturbDate](#donotdisturbdate) | 是 | 回调返回免打扰时间选项变更。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onDoNotDisturbDateChangeCallback() {
console.info('===> onDoNotDisturbDateChange in test');
}
var subscriber = {
onDoNotDisturbDateChange: onDoNotDisturbDateChangeCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
### onEnabledNotificationChanged<sup>8+</sup>
onEnabledNotificationChanged?:(callbackData: [EnabledNotificationCallbackData](#enablednotificationcallbackdata))
监听应用通知使能变化。
**系统能力**:SystemCapability.Notification.Notification
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ------------------------ | ---- | -------------------------- |
| callback | AsyncCallback\<[EnabledNotificationCallbackData](#enablednotificationcallbackdata)\> | 是 | 回调返回监听到的应用信息。 |
**示例:**
```javascript
function subscribeCallback(err) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("subscribeCallback");
}
};
function onEnabledNotificationChangedCallback(err, callbackData) {
if (err.code) {
console.info("subscribe failed " + JSON.stringify(err));
} else {
console.info("bundle: ", callbackData.bundle);
console.info("uid: ", callbackData.uid);
console.info("enable: ", callbackData.enable);
}
};
var subscriber = {
onEnabledNotificationChanged: onEnabledNotificationChangedCallback
};
Notification.subscribe(subscriber, subscribeCallback);
```
## SubscribeCallbackData
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| --------------- | ---- | --- | ------------------------------------------------- | ---- | -------- |
| request | 是 | 否 | [NotificationRequest](#notificationrequest) | 是 | 通知内容。 |
| sortingMap | 是 | 否 | [NotificationSortingMap](#notificationsortingmap) | 否 | 排序信息。 |
| reason | 是 | 否 | number | 否 | 删除原因。 |
| sound | 是 | 否 | string | 否 | 通知声音。 |
| vibrationValues | 是 | 否 | Array\<number\> | 否 | 通知震动。 |
## EnabledNotificationCallbackData<sup>8+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| ------ | ---- | --- | ------- | ---- | ---------------- |
| bundle | 是 | 否 | string | 是 | 应用的包名。 |
| uid | 是 | 否 | number | 是 | 应用的uid。 |
| enable | 是 | 否 | boolean | 是 | 应用通知使能状态。 |
\ No newline at end of file
# 通知模板
> **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## NotificationTemplate
模板信息
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.Notification
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| ---- | ---------------------- | ---- | ---- | ---------- |
| name | string | 是 | 是 | 模板名称。 |
| data | {[key:string]: Object} | 是 | 是 | 模板数据。 |
\ No newline at end of file
# NotificationUserInput
> **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## NotificationUserInput
**系统能力**:SystemCapability.Notification.Notification
| 名称 | 可读 | 可写 | 类型 | 必填 | 描述 |
| -------- | --- | ---- | ------ | ---- | ----------------------------- |
| inputKey | 是 | 是 | string | 是 | 用户输入时用于标识此输入的key。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册