未验证 提交 b053f567 编写于 作者: O openharmony_ci 提交者: Gitee

!2585 Merge children docs into CommonEvent & Notification

Merge pull request !2585 from xuzhihao/master
# 公共事件数据
> **说明:**
> 本模块首批接口从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
# 通知按钮
> **说明:**
> 本模块首批接口从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.
先完成此消息的编辑!
想要评论请 注册