提交 f33f052f 编写于 作者: L Leon

事件通知文档更新

Signed-off-by: NLeon <yangliang36@huawei.com>
上级 be87c2e7
# @ohos.events.emitter (Emitter) # @ohos.events.emitter (Emitter)
本模块提供发送和处理进程内事件的能力,包括对持续订阅事件或单次订阅事件的处理,取消订阅事件,发送事件到事件队列 本模块提供了在同一进程不同线程间,或同一进程同一线程内,发送和处理事件的能力,包括持续订阅事件、单次订阅事件、取消订阅事件,以及发送事件到事件队列的能力
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 7开始支持。 > 本模块首批接口从API version 7开始支持。后续版本新增接口,采用上角标单独标记接口的起始版本。
>
> 本模块接口在FA模型及Stage模型下均可使用。
## 导入模块 ## 导入模块
...@@ -14,22 +16,22 @@ import emitter from '@ohos.events.emitter' ...@@ -14,22 +16,22 @@ import emitter from '@ohos.events.emitter'
## 权限列表 ## 权限列表
权限要求。
## emitter.on ## emitter.on
on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
持续订阅某个事件以及接收事件的回调处理 持续订阅指定的事件,并在接收到该事件时,执行对应的回调处理函数
**系统能力**: SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | --------------------------------------- | | -------- | ----------------------------------- | ---- | ------------------------------------------------------ |
| event | [InnerEvent](#innerevent) | 是 | 持续订阅的事件,其中EventPriority不生效 | | event | [InnerEvent](#innerevent) | 是 | 持续订阅的事件,其中[EventPriority](#eventpriority),在订阅事件时无需指定,也不生效 |
| callback | Callback\<[EventData](#eventdata)\> | 是 | 接收订阅事件时的回调处理 | | callback | Callback\<[EventData](#eventdata)\> | 是 | 接收到该事件时需要执行的回调处理函数 |
**示例:** **示例:**
...@@ -37,26 +39,28 @@ on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata) ...@@ -37,26 +39,28 @@ on(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)
let innerEvent = { let innerEvent = {
eventId: 1 eventId: 1
}; };
function EmitterCallback(eventData) {
// 收到eventId为1的事件后执行该回调函数
function emitterCallback() {
console.info('callback'); console.info('callback');
} }
emitter.on(innerEvent, EmitterCallback); emitter.on(innerEvent, emitterCallback);
``` ```
## emitter.once ## emitter.once
once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdata)\>): void
单次订阅某个事件以及接收事件的回调处理,接收到回调处理后自动取消订阅。 单次订阅指定的事件,并在接收到该事件并执行完相应的回调函数后,自动取消订阅。
**系统能力**: SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------------------- | ---- | --------------------------------------- | | -------- | ----------------------------------- | ---- | ------------------------------------------------------------------------------ |
| event | [InnerEvent](#innerevent) | 是 | 单次订阅的事件,其中EventPriority不生效 | | event | [InnerEvent](#innerevent) | 是 | 单次订阅的事件,其中[EventPriority](#eventpriority),在订阅事件时无需指定,也不生效 |
| callback | Callback\<[EventData](#eventdata)\> | 是 | 接收订阅事件时的回调处理 | | callback | Callback\<[EventData](#innerevent)\> | 是 | 接收到该事件时需要执行的回调处理函数 |
**示例:** **示例:**
...@@ -64,19 +68,21 @@ once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdat ...@@ -64,19 +68,21 @@ once(event: [InnerEvent](#innerevent), callback: Callback\<[EventData](#eventdat
let innerEvent = { let innerEvent = {
eventId: 1 eventId: 1
}; };
function EmitterCallback(eventData) {
// 收到eventId为1的事件后执行该回调函数
function emitterCallback() {
console.info('once callback'); console.info('once callback');
}; };
emitter.once(innerEvent, EmitterCallback); emitter.once(innerEvent, emitterCallback);
``` ```
## emitter.off ## emitter.off
off(eventId: number): void off(eventId: number): void
取消订阅某个事件 取消所有针对该事件ID的订阅
**系统能力**: SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
**参数:** **参数:**
...@@ -92,17 +98,17 @@ emitter.off(1); ...@@ -92,17 +98,17 @@ emitter.off(1);
## emitter.emit ## emitter.emit
emit(event: InnerEvent, data?: EventData): void emit(event: [InnerEvent](#innerevent), data?: [EventData](#eventdata)): void
发送一个事件到事件队列 发送指定的事件
**系统能力**: SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------- | ---- | -------------- | | ------ | ------------------------- | ---- | ------------- |
| event | [InnerEvent](#innerevent) | 是 | 发送的事件 | | event | [InnerEvent](#innerevent) | 是 | 发送的事件,其中[EventPriority](#eventpriority)用于指定事件被发送的优先级 |
| data | [EventData](#eventdata) | 否 | 事件携带的数据 | | data | [EventData](#eventdata) | 否 | 事件携带的数据 |
**示例:** **示例:**
...@@ -112,19 +118,22 @@ let eventData = { ...@@ -112,19 +118,22 @@ let eventData = {
data: { data: {
"content": "c", "content": "c",
"id": 1, "id": 1,
}}; }
};
let innerEvent = { let innerEvent = {
eventId: 1, eventId: 1,
priority: emitter.EventPriority.HIGH priority: emitter.EventPriority.HIGH
}; };
emitter.emit(innerEvent, eventData); emitter.emit(innerEvent, eventData);
``` ```
## EventPriority ## EventPriority
用于表示事件被投递的优先级。 用于表示事件被发送的优先级。
**系统能力**: 以下各项对应的系统能力均为 SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| --------- | ---- | --------------------------------------------------- | | --------- | ---- | --------------------------------------------------- |
...@@ -135,20 +144,20 @@ emitter.emit(innerEvent, eventData); ...@@ -135,20 +144,20 @@ emitter.emit(innerEvent, eventData);
## InnerEvent ## InnerEvent
进程内的事件 订阅或发送的事件,订阅事件时`EventPriority`不生效
**系统能力**: 以下各项对应的系统能力均为 SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | ------------------------------- | ---- | ---- | ---------------------------------- | | -------- | ------------------------------- | ---- | ---- | ------------------------------ |
| eventId | number | 是 | 是 | 事件ID,由开发者定义用来辨别事件。 | | eventId | number | 是 | 是 | 事件ID,由开发者定义用来辨别事件。 |
| priority | [EventPriority](#eventpriority) | 是 | 是 | 事件被投递的优先级。 | | priority | [EventPriority](#eventpriority) | 是 | 是 | 事件被投递的优先级。 |
## EventData ## EventData
发送事件时传递的数据。 发送事件时传递的数据。
**系统能力**: 以下各项对应的系统能力均为 SystemCapability.Notification.Emitter **系统能力**: `SystemCapability.Notification.Emitter`
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ---- | ------------------ | ---- | ---- | -------------- | | ---- | ------------------ | ---- | ---- | -------------- |
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
本模块提供后台代理提醒的能力。 本模块提供后台代理提醒的能力。
开发应用时,开发者可以调用后台提醒发布的接口创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。 开发应用时,开发者可以调用相关接口创建定时提醒,包括倒计时、日历、闹钟这三类提醒类型。使用后台代理提醒能力后,应用被冻结或退出后,计时和弹出提醒的功能将被后台系统服务代理。
> **说明:** > **说明:**
> >
...@@ -13,34 +13,37 @@ ...@@ -13,34 +13,37 @@
## 导入模块 ## 导入模块
```js ```ts
import reminderAgent from'@ohos.reminderAgent'; import reminderAgent from'@ohos.reminderAgent';
``` ```
## reminderAgent.publishReminder ## reminderAgent.publishReminder
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number&gt;): void ```ts
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void
```
发布一个后台代理提醒,使用callback方式实现异步调用,该方法需要申请通知弹窗[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。 发布一个后台代理提醒,使用回调的方式实现异步调用,该方法需要申请通知弹窗权限[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。
**需要权限**ohos.permission.PUBLISH_AGENT_REMINDER **需要权限**`ohos.permission.PUBLISH_AGENT_REMINDER`
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 | | reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 异步回调,返回当前发布的提醒的reminderId。 | | callback | AsyncCallback\<number\> | 是 | 异步回调,返回当前发布的提醒的id。 |
**示例** **示例**
```js ```ts
let timer = { let timer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10 triggerTimeInSeconds: 10
} }
reminderAgent.publishReminder(timer, (err, reminderId) => { reminderAgent.publishReminder(timer, (err, reminderId) => {
console.log("callback, reminderId = " + reminderId); console.log("callback, reminderId = " + reminderId);
}); });
...@@ -49,13 +52,15 @@ publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number& ...@@ -49,13 +52,15 @@ publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number&
## reminderAgent.publishReminder ## reminderAgent.publishReminder
publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ```ts
publishReminder(reminderReq: ReminderRequest): Promise<number>
```
发布一个后台代理提醒,使用Promise方式实现异步调用,该方法需要申请通知弹窗[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。 发布一个后台代理提醒,使用Promise方式实现异步调用,该方法需要申请通知弹窗权限[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。
**需要权限**ohos.permission.PUBLISH_AGENT_REMINDER **需要权限**`ohos.permission.PUBLISH_AGENT_REMINDER`
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -65,14 +70,15 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ...@@ -65,14 +70,15 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt;
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | 返回提醒的reminderId。 | | Promise\<number\> | 返回提醒的Id。 |
**示例** **示例**
```js ```ts
let timer = { let timer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10 triggerTimeInSeconds: 10
} }
reminderAgent.publishReminder(timer).then((reminderId) => { reminderAgent.publishReminder(timer).then((reminderId) => {
console.log("promise, reminderId = " + reminderId); console.log("promise, reminderId = " + reminderId);
}); });
...@@ -81,22 +87,24 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ...@@ -81,22 +87,24 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt;
## reminderAgent.cancelReminder ## reminderAgent.cancelReminder
cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void ```ts
cancelReminder(reminderId: number, callback: AsyncCallback<void>): void
```
取消指定id的提醒,使用callback方式实现异步调用。 取消指定id的提醒,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderId | number | 是 | 目标reminder的id号,[publishReminder](#reminderagentpublishreminder)方法调用成功后获得。 | | reminderId | number | 是 | 目标reminder的id号,[publishReminder](#reminderagentpublishreminder)方法调用成功后获得。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**示例** **示例**
```js ```ts
reminderAgent.cancelReminder(1, (err, data) => { reminderAgent.cancelReminder(1, (err, data) => {
console.log("cancelReminder callback"); console.log("cancelReminder callback");
}); });
...@@ -105,11 +113,13 @@ reminderAgent.cancelReminder(1, (err, data) => { ...@@ -105,11 +113,13 @@ reminderAgent.cancelReminder(1, (err, data) => {
## reminderAgent.cancelReminder ## reminderAgent.cancelReminder
cancelReminder(reminderId: number): Promise&lt;void&gt; ```ts
cancelReminder(reminderId: number): Promise<void>
```
取消指定id的提醒,使用Promise方式实现异步调用。 取消指定id的提醒,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
...@@ -121,34 +131,35 @@ cancelReminder(reminderId: number): Promise&lt;void&gt; ...@@ -121,34 +131,35 @@ cancelReminder(reminderId: number): Promise&lt;void&gt;
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**示例** **示例**
```js ```ts
reminderAgent.cancelReminder(1).then(() => { reminderAgent.cancelReminder(1).then(() => {
console.log("cancelReminder promise"); console.log("cancelReminder promise");
}); });
``` ```
## reminderAgent.getValidReminders ## reminderAgent.getValidReminders
getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;): void ```ts
getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void
```
获取当前应用已设置的所有有效(未过期)的提醒,使用callback方式实现异步调用。 获取当前应用已设置的所有有效(未过期)的提醒,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | 是 | 异步回调,返回当前应用已设置的所有有效(未过期)的提醒。 | | callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)\>\> | 是 | 异步回调,返回当前应用已设置的所有有效(未过期)的提醒。 |
**示例** **示例**
```js ```ts
reminderAgent.getValidReminders((err, reminders) => { reminderAgent.getValidReminders((err, reminders) => {
console.log("callback, getValidReminders length = " + reminders.length); console.log("callback, getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) { for (let i = 0; i < reminders.length; i++) {
...@@ -178,21 +189,23 @@ reminderAgent.getValidReminders((err, reminders) => { ...@@ -178,21 +189,23 @@ reminderAgent.getValidReminders((err, reminders) => {
## reminderAgent.getValidReminders ## reminderAgent.getValidReminders
getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt; ```ts
getValidReminders(): Promise<Array<ReminderRequest>>
```
获取当前应用已设置的所有有效(未过期)的提醒,使用Promise方式实现异步调用。 获取当前应用已设置的所有有效(未过期)的提醒,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | 返回当前应用已设置的所有有效(未过期)的提醒。 | | Promise\<Array\<[ReminderRequest](#reminderrequest)\>\> | 返回当前应用已设置的所有有效(未过期)的提醒。 |
**示例** **示例**
```js ```ts
reminderAgent.getValidReminders().then((reminders) => { reminderAgent.getValidReminders().then((reminders) => {
console.log("promise, getValidReminders length = " + reminders.length); console.log("promise, getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) { for (let i = 0; i < reminders.length; i++) {
...@@ -222,21 +235,23 @@ reminderAgent.getValidReminders().then((reminders) => { ...@@ -222,21 +235,23 @@ reminderAgent.getValidReminders().then((reminders) => {
## reminderAgent.cancelAllReminders ## reminderAgent.cancelAllReminders
cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void ```ts
cancelAllReminders(callback: AsyncCallback<void>): void
```
取消当前应用所有的提醒,使用callback方式实现异步调用。 取消当前应用所有的提醒,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**示例** **示例**
```js ```ts
reminderAgent.cancelAllReminders((err, data) =>{ reminderAgent.cancelAllReminders((err, data) =>{
console.log("cancelAllReminders callback") console.log("cancelAllReminders callback")
}) })
...@@ -245,45 +260,48 @@ reminderAgent.cancelAllReminders((err, data) =>{ ...@@ -245,45 +260,48 @@ reminderAgent.cancelAllReminders((err, data) =>{
## reminderAgent.cancelAllReminders ## reminderAgent.cancelAllReminders
cancelAllReminders(): Promise&lt;void&gt; ```ts
cancelAllReminders(): Promise<void>
```
取消当前应用所有的提醒,使用Promise方式实现异步调用。 取消当前应用所有的提醒,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**示例** **示例**
```js ```ts
reminderAgent.cancelAllReminders().then(() => { reminderAgent.cancelAllReminders().then(() => {
console.log("cancelAllReminders promise") console.log("cancelAllReminders promise")
}) })
``` ```
## reminderAgent.addNotificationSlot ## reminderAgent.addNotificationSlot
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;): void ```ts
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void
```
添加一个NotificationSlot,使用callback方式实现异步调用。 添加一个NotificationSlot,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification&nbsp;slot实例,仅支持设置其type属性。 | | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification\.slot实例,仅支持设置其type属性。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
let mySlot = { let mySlot = {
...@@ -297,27 +315,29 @@ reminderAgent.addNotificationSlot(mySlot, (err, data) => { ...@@ -297,27 +315,29 @@ reminderAgent.addNotificationSlot(mySlot, (err, data) => {
## reminderAgent.addNotificationSlot ## reminderAgent.addNotificationSlot
addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt; ```ts
addNotificationSlot(slot: NotificationSlot): Promise<void>
```
添加一个NotificationSlot,使用Promise方式实现异步调用。 添加一个NotificationSlot,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification&nbsp;slot实例,仅支持设置其type属性。 | | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification\.slot实例,仅支持设置其type属性。 |
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
let mySlot = { let mySlot = {
...@@ -331,22 +351,24 @@ reminderAgent.addNotificationSlot(mySlot).then(() => { ...@@ -331,22 +351,24 @@ reminderAgent.addNotificationSlot(mySlot).then(() => {
## reminderAgent.removeNotificationSlot ## reminderAgent.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback&lt;void&gt;): void ```ts
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void
```
删除目标NotificationSlot,使用callback方式实现异步调用。 删除目标NotificationSlot,使用callback方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification&nbsp;slot的类型。 | | slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification\.slot的类型。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => {
...@@ -357,27 +379,29 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, ...@@ -357,27 +379,29 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION,
## reminderAgent.removeNotificationSlot ## reminderAgent.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt; ```ts
removeNotificationSlot(slotType: notification.SlotType): Promise<void>
```
删除目标NotificationSlot,使用Promise方式实现异步调用。 删除目标NotificationSlot,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification&nbsp;slot的类型。 | | slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification\.slot的类型。 |
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => {
...@@ -390,7 +414,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION). ...@@ -390,7 +414,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
按钮的类型。 按钮的类型。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -402,7 +426,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION). ...@@ -402,7 +426,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
提醒的类型。 提醒的类型。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -415,7 +439,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION). ...@@ -415,7 +439,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
用于设置弹出的提醒通知信息上显示的按钮类型和标题。 用于设置弹出的提醒通知信息上显示的按钮类型和标题。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -427,7 +451,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION). ...@@ -427,7 +451,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
点击提醒通知后跳转的目标ability信息。 点击提醒通知后跳转的目标ability信息。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -439,7 +463,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION). ...@@ -439,7 +463,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
全屏显示提醒到达时自动拉起的目标ability信息,该接口预留。 全屏显示提醒到达时自动拉起的目标ability信息,该接口预留。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -451,7 +475,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION). ...@@ -451,7 +475,7 @@ reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).
提醒实例对象,用于设置提醒类型、响铃时长等具体信息。 提醒实例对象,用于设置提醒类型、响铃时长等具体信息。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -476,13 +500,13 @@ ReminderRequestCalendar extends ReminderRequest ...@@ -476,13 +500,13 @@ ReminderRequestCalendar extends ReminderRequest
日历实例对象,用于设置提醒的时间。 日历实例对象,用于设置提醒的时间。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dateTime | [LocalDateTime](#localdatetime) | 是 | 指明提醒的目标时间。 | | dateTime | [LocalDateTime](#localdatetime) | 是 | 指明提醒的目标时间。 |
| repeatMonths | Array&lt;number&gt; | 否 | 指明重复提醒的月份。 | | repeatMonths | Array\<number\> | 否 | 指明重复提醒的月份。 |
| repeatDays | Array&lt;number&gt; | 否 | 指明重复提醒的日期。 | | repeatDays | Array\<number\> | 否 | 指明重复提醒的日期。 |
## ReminderRequestAlarm ## ReminderRequestAlarm
...@@ -491,13 +515,13 @@ ReminderRequestAlarm extends ReminderRequest ...@@ -491,13 +515,13 @@ ReminderRequestAlarm extends ReminderRequest
闹钟实例对象,用于设置提醒的时间。 闹钟实例对象,用于设置提醒的时间。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| hour | number | 是 | 指明提醒的目标时刻。 | | hour | number | 是 | 指明提醒的目标时刻。 |
| minute | number | 是 | 指明提醒的目标分钟。 | | minute | number | 是 | 指明提醒的目标分钟。 |
| daysOfWeek | Array&lt;number&gt; | 否 | 指明每周哪几天需要重复提醒。范围为周一到周末,对应数字为1到7。 | | daysOfWeek | Array\<number\> | 否 | 指明每周哪几天需要重复提醒。范围为周一到周末,对应数字为1到7。 |
## ReminderRequestTimer ## ReminderRequestTimer
...@@ -506,7 +530,7 @@ ReminderRequestTimer extends ReminderRequest ...@@ -506,7 +530,7 @@ ReminderRequestTimer extends ReminderRequest
倒计时实例对象,用于设置提醒的时间。 倒计时实例对象,用于设置提醒的时间。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -517,7 +541,7 @@ ReminderRequestTimer extends ReminderRequest ...@@ -517,7 +541,7 @@ ReminderRequestTimer extends ReminderRequest
用于日历类提醒设置时指定时间信息。 用于日历类提醒设置时指定时间信息。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
本模块提供后台代理提醒的能力。 本模块提供后台代理提醒的能力。
开发应用时,开发者可以调用后台提醒发布的接口创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。 开发应用时,开发者可以调用相关接口创建定时提醒,包括倒计时、日历、闹钟这三类提醒类型。使用后台代理提醒能力后,应用被冻结或退出后,计时和弹出提醒的功能将被后台系统服务代理。
> **说明:** > **说明:**
> >
...@@ -11,27 +11,29 @@ ...@@ -11,27 +11,29 @@
## 导入模块 ## 导入模块
``` ```ts
import reminderAgentManager from'@ohos.reminderAgentManager'; import reminderAgentManager from'@ohos.reminderAgentManager';
``` ```
## reminderAgentManager.publishReminder ## reminderAgentManager.publishReminder
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number&gt;): void ```ts
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void
```
发布一个后台代理提醒,使用callback方式实现异步调用,该方法需要申请通知弹窗[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。 发布一个后台代理提醒,使用回调的方式实现异步调用,该方法需要申请通知弹窗权限[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。
**需要权限**ohos.permission.PUBLISH_AGENT_REMINDER **需要权限**`ohos.permission.PUBLISH_AGENT_REMINDER`
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 | | reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 |
| callback | AsyncCallback&lt;number&gt; | 是 | 异步回调,返回当前发布的提醒的reminderId。 | | callback | AsyncCallback\<number\> | 是 | 异步回调,返回当前发布的提醒的id。 |
**错误码:** **错误码:**
...@@ -43,11 +45,12 @@ publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number& ...@@ -43,11 +45,12 @@ publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number&
| 1700002 | The number of reminders exceeds the limit. | | 1700002 | The number of reminders exceeds the limit. |
**示例** **示例**
```js ```ts
let timer = { let timer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10 triggerTimeInSeconds: 10
} }
try { try {
reminderAgentManager.publishReminder(timer, (err, reminderId) => { reminderAgentManager.publishReminder(timer, (err, reminderId) => {
if (err) { if (err) {
...@@ -64,13 +67,15 @@ try { ...@@ -64,13 +67,15 @@ try {
## reminderAgentManager.publishReminder ## reminderAgentManager.publishReminder
publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ```ts
publishReminder(reminderReq: ReminderRequest): Promise<number>
```
发布一个后台代理提醒,使用Promise方式实现异步调用,该方法需要申请通知弹窗[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。 发布一个后台代理提醒,使用`Promise`的方式实现异步调用,该方法需要申请通知弹窗权限[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。
**需要权限**ohos.permission.PUBLISH_AGENT_REMINDER **需要权限**`ohos.permission.PUBLISH_AGENT_REMINDER`
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
...@@ -80,7 +85,7 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ...@@ -80,7 +85,7 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt;
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | 返回提醒的reminderId。 | | Promise\<number\> | 返回提醒的id。 |
**错误码:** **错误码:**
...@@ -92,11 +97,12 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ...@@ -92,11 +97,12 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt;
| 1700002 | The number of reminders exceeds the limit. | | 1700002 | The number of reminders exceeds the limit. |
**示例** **示例**
```js ```ts
let timer = { let timer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10 triggerTimeInSeconds: 10
} }
try { try {
reminderAgentManager.publishReminder(timer).then((reminderId) => { reminderAgentManager.publishReminder(timer).then((reminderId) => {
console.log("promise, reminderId = " + reminderId); console.log("promise, reminderId = " + reminderId);
...@@ -111,18 +117,20 @@ try { ...@@ -111,18 +117,20 @@ try {
## reminderAgentManager.cancelReminder ## reminderAgentManager.cancelReminder
cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void ```ts
cancelReminder(reminderId: number, callback: AsyncCallback<void>): void
```
取消指定id的提醒,使用callback方式实现异步调用。 取消指定id的提醒,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderId | number | 是 | 目标reminder的id号。 | | reminderId | number | 是 | 目标提醒的id号。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**错误码:** **错误码:**
...@@ -135,7 +143,7 @@ cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -135,7 +143,7 @@ cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
```js ```ts
try { try {
reminderAgentManager.cancelReminder(1, (err, data) => { reminderAgentManager.cancelReminder(1, (err, data) => {
if (err) { if (err) {
...@@ -152,23 +160,25 @@ try { ...@@ -152,23 +160,25 @@ try {
## reminderAgentManager.cancelReminder ## reminderAgentManager.cancelReminder
cancelReminder(reminderId: number): Promise&lt;void&gt; ```ts
cancelReminder(reminderId: number): Promise<void>
```
取消指定id的提醒,使用Promise方式实现异步调用。 取消指定id的提醒,使用`Promise`方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| reminderId | number | 是 | 目标reminder的id号。 | | reminderId | number | 是 | 目标提醒的id号。 |
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | PPromise\<void\> | Promise类型异步回调。 |
**错误码:** **错误码:**
...@@ -181,7 +191,7 @@ cancelReminder(reminderId: number): Promise&lt;void&gt; ...@@ -181,7 +191,7 @@ cancelReminder(reminderId: number): Promise&lt;void&gt;
**示例** **示例**
```js ```ts
try { try {
reminderAgentManager.cancelReminder(1).then(() => { reminderAgentManager.cancelReminder(1).then(() => {
console.log("cancelReminder promise"); console.log("cancelReminder promise");
...@@ -193,20 +203,22 @@ try { ...@@ -193,20 +203,22 @@ try {
}; };
``` ```
## reminderAgentManager.getValidReminders ## reminderAgentManager.getValidReminders
getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;): void ```ts
getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void
```
获取当前应用已设置的所有有效(未过期)的提醒,使用callback方式实现异步调用。 获取当前应用已设置的所有有效(未过期)的提醒,使用回调方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | 是 | 异步回调,返回当前应用已设置的所有有效(未过期)的提醒。 | | callback | AsyncCallback\<Array\<[ReminderRequest](#reminderrequest)\>\> | 是 | 异步回调,返回当前应用已设置的所有有效(未过期)的提醒。 |
**错误码:** **错误码:**
...@@ -218,7 +230,7 @@ getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;): ...@@ -218,7 +230,7 @@ getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;):
**示例** **示例**
```js ```ts
try { try {
reminderAgentManager.getValidReminders((err, reminders) => { reminderAgentManager.getValidReminders((err, reminders) => {
if (err) { if (err) {
...@@ -253,20 +265,21 @@ try { ...@@ -253,20 +265,21 @@ try {
}; };
``` ```
## reminderAgentManager.getValidReminders ## reminderAgentManager.getValidReminders
getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt; ```ts
getValidReminders(): Promise<Array<ReminderRequest>>
```
获取当前应用已设置的所有有效(未过期)的提醒,使用Promise方式实现异步调用。 获取当前应用已设置的所有有效(未过期)的提醒,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | 返回当前应用已设置的所有有效(未过期)的提醒。 | | Promise\<Array\<[ReminderRequest](#reminderrequest)\>\> | 返回当前应用已设置的所有有效(未过期)的提醒。 |
**错误码:** **错误码:**
...@@ -278,7 +291,7 @@ getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt; ...@@ -278,7 +291,7 @@ getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt;
**示例** **示例**
```js ```ts
try { try {
reminderAgentManager.getValidReminders().then((reminders) => { reminderAgentManager.getValidReminders().then((reminders) => {
console.log("promise, getValidReminders length = " + reminders.length); console.log("promise, getValidReminders length = " + reminders.length);
...@@ -314,17 +327,19 @@ try { ...@@ -314,17 +327,19 @@ try {
## reminderAgentManager.cancelAllReminders ## reminderAgentManager.cancelAllReminders
cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void ```ts
cancelAllReminders(callback: AsyncCallback<void>): void
```
取消当前应用所有的提醒,使用callback方式实现异步调用。 取消当前应用所有的提醒,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**错误码:** **错误码:**
...@@ -336,7 +351,7 @@ cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void ...@@ -336,7 +351,7 @@ cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
```js ```ts
try { try {
reminderAgentManager.cancelAllReminders((err, data) =>{ reminderAgentManager.cancelAllReminders((err, data) =>{
if (err) { if (err) {
...@@ -353,17 +368,19 @@ try { ...@@ -353,17 +368,19 @@ try {
## reminderAgentManager.cancelAllReminders ## reminderAgentManager.cancelAllReminders
cancelAllReminders(): Promise&lt;void&gt; ```ts
cancelAllReminders(): Promise<void>
```
取消当前应用所有的提醒,使用Promise方式实现异步调用。 取消当前应用所有的提醒,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**错误码:** **错误码:**
...@@ -375,7 +392,7 @@ cancelAllReminders(): Promise&lt;void&gt; ...@@ -375,7 +392,7 @@ cancelAllReminders(): Promise&lt;void&gt;
**示例** **示例**
```js ```ts
try { try {
reminderAgentManager.cancelAllReminders().then(() => { reminderAgentManager.cancelAllReminders().then(() => {
console.log("cancelAllReminders promise") console.log("cancelAllReminders promise")
...@@ -390,22 +407,24 @@ try { ...@@ -390,22 +407,24 @@ try {
## reminderAgentManager.addNotificationSlot ## reminderAgentManager.addNotificationSlot
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;): void ```ts
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void
```
添加一个NotificationSlot,使用callback方式实现异步调用。 添加一个NotificationSlot,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification&nbsp;slot实例,仅支持设置其type属性。 | | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification\.slot实例,仅支持设置其type属性。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
let mySlot = { let mySlot = {
...@@ -427,27 +446,29 @@ try { ...@@ -427,27 +446,29 @@ try {
## reminderAgentManager.addNotificationSlot ## reminderAgentManager.addNotificationSlot
addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt; ```ts
addNotificationSlot(slot: NotificationSlot): Promise<void>
```
添加一个NotificationSlot,使用Promise方式实现异步调用。 添加一个NotificationSlot,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification&nbsp;slot实例,仅支持设置其type属性。 | | slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification\.slot实例,仅支持设置其type属性。 |
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
let mySlot = { let mySlot = {
...@@ -467,22 +488,24 @@ try { ...@@ -467,22 +488,24 @@ try {
## reminderAgentManager.removeNotificationSlot ## reminderAgentManager.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback&lt;void&gt;): void ```ts
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void
```
删除目标NotificationSlot,使用callback方式实现异步调用。 删除目标NotificationSlot,使用回调的方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification&nbsp;slot的类型。 | | slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification\.slot的类型。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 | | callback | AsyncCallback\<void\> | 是 | 异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
try { try {
...@@ -501,27 +524,29 @@ try { ...@@ -501,27 +524,29 @@ try {
## reminderAgentManager.removeNotificationSlot ## reminderAgentManager.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt; ```ts
removeNotificationSlot(slotType: notification.SlotType): Promise<void>
```
删除目标NotificationSlot,使用Promise方式实现异步调用。 删除目标NotificationSlot,使用Promise方式实现异步调用。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
**参数** **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification&nbsp;slot的类型。 | | slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification\.slot的类型。 |
**返回值** **返回值**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 | | Promise\<void\> | Promise类型异步回调。 |
**示例** **示例**
```js ```ts
import notification from '@ohos.notification' import notification from '@ohos.notification'
try { try {
...@@ -539,7 +564,7 @@ try { ...@@ -539,7 +564,7 @@ try {
按钮的类型。 按钮的类型。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -551,7 +576,7 @@ try { ...@@ -551,7 +576,7 @@ try {
提醒的类型。 提醒的类型。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 值 | 说明 | | 名称 | 值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
...@@ -564,7 +589,7 @@ try { ...@@ -564,7 +589,7 @@ try {
用于设置弹出的提醒通知信息上显示的按钮类型和标题。 用于设置弹出的提醒通知信息上显示的按钮类型和标题。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -574,9 +599,9 @@ try { ...@@ -574,9 +599,9 @@ try {
## WantAgent ## WantAgent
点击提醒通知后跳转的目标ability信息。 点击提醒通知后跳转的目标`ability`信息。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -588,7 +613,7 @@ try { ...@@ -588,7 +613,7 @@ try {
全屏显示提醒到达时自动拉起的目标ability信息,该接口预留。 全屏显示提醒到达时自动拉起的目标ability信息,该接口预留。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -600,7 +625,7 @@ try { ...@@ -600,7 +625,7 @@ try {
提醒实例对象,用于设置提醒类型、响铃时长等具体信息。 提醒实例对象,用于设置提醒类型、响铃时长等具体信息。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -625,13 +650,13 @@ ReminderRequestCalendar extends ReminderRequest ...@@ -625,13 +650,13 @@ ReminderRequestCalendar extends ReminderRequest
日历实例对象,用于设置提醒的时间。 日历实例对象,用于设置提醒的时间。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| dateTime | [LocalDateTime](#localdatetime) | 是 | 指明提醒的目标时间。 | | dateTime | [LocalDateTime](#localdatetime) | 是 | 指明提醒的目标时间。 |
| repeatMonths | Array&lt;number&gt; | 否 | 指明重复提醒的月份。 | | repeatMonths | Array\<number\> | 否 | 指明重复提醒的月份。 |
| repeatDays | Array&lt;number&gt; | 否 | 指明重复提醒的日期。 | | repeatDays | Array\<number\> | 否 | 指明重复提醒的日期。 |
## ReminderRequestAlarm ## ReminderRequestAlarm
...@@ -640,13 +665,13 @@ ReminderRequestAlarm extends ReminderRequest ...@@ -640,13 +665,13 @@ ReminderRequestAlarm extends ReminderRequest
闹钟实例对象,用于设置提醒的时间。 闹钟实例对象,用于设置提醒的时间。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| hour | number | 是 | 指明提醒的目标时刻。 | | hour | number | 是 | 指明提醒的目标时刻。 |
| minute | number | 是 | 指明提醒的目标分钟。 | | minute | number | 是 | 指明提醒的目标分钟。 |
| daysOfWeek | Array&lt;number&gt; | 否 | 指明每周哪几天需要重复提醒。范围为周一到周末,对应数字为1到7。 | | daysOfWeek | Array\<number\> | 否 | 指明每周哪几天需要重复提醒。范围为周一到周末,对应数字为1到7。 |
## ReminderRequestTimer ## ReminderRequestTimer
...@@ -655,7 +680,7 @@ ReminderRequestTimer extends ReminderRequest ...@@ -655,7 +680,7 @@ ReminderRequestTimer extends ReminderRequest
倒计时实例对象,用于设置提醒的时间。 倒计时实例对象,用于设置提醒的时间。
**系统能力**SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -666,7 +691,7 @@ ReminderRequestTimer extends ReminderRequest ...@@ -666,7 +691,7 @@ ReminderRequestTimer extends ReminderRequest
用于日历类提醒设置时指定时间信息。 用于日历类提醒设置时指定时间信息。
**系统能力**以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent **系统能力**`SystemCapability.Notification.ReminderAgent`
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
......
...@@ -6,27 +6,27 @@ ...@@ -6,27 +6,27 @@
Want action is null Want action is null
**错误描述** **错误描述**
发送事件的want中的Action属性为空时系统会产生此错误码。 发送事件的`want`中的`Action`属性为空时系统会产生此错误码。
**可能原因** **可能原因**
发送事件的want中的Action属性为空。 发送事件的`want`中的`Action`属性为空。
**处理步骤** **处理步骤**
检查传入want的Action属性是否为空。 检查传入`want``Action`属性是否为空。
## 1500002 沙箱用无法发送公共事件 ## 1500002 沙箱用无法发送公共事件
**错误信息** **错误信息**
sandbox application can not send common event sandbox application can not send common event
**错误描述** **错误描述**
沙箱用无法发送公共事件。 沙箱用无法发送公共事件。
**可能原因** **可能原因**
事件发送方应用为沙箱应用,发送事件会被拦截。 事件发送方应用为沙箱应用,发送事件会被拦截。
**处理步骤** **处理步骤**
检查事件发送是否为沙箱应用,若是,则无法发送。请不要使用沙箱应用发送事件 沙箱应用无法发送公共事件,发送公共事件前确认是否为沙箱应用
## 1500003 事件发送频率过高 ## 1500003 事件发送频率过高
...@@ -54,7 +54,7 @@ not System services or System app ...@@ -54,7 +54,7 @@ not System services or System app
非系统应用或非系统服务发送系统公共事件。 非系统应用或非系统服务发送系统公共事件。
**处理步骤** **处理步骤**
检查应用是否为系统应用或者系统服务;若不是,则无法发送 确认当前应用是否为系统应用,或当前服务是否为系统服务
## 1500005 未找到订阅者 ## 1500005 未找到订阅者
...@@ -73,24 +73,24 @@ subscriber can not found ...@@ -73,24 +73,24 @@ subscriber can not found
## 1500006 无效userId ## 1500006 无效userId
**错误信息** **错误信息**
usreId is invalid userId is invalid
**错误描述** **错误描述**
无效的userId。 无效的userId。
**可能原因** **可能原因**
和系统userId不一致或不是系统应用或子系统进程。 和系统`userId`不一致或不是系统应用或系统服务进程。
**处理步骤** **处理步骤**
检查当前userId是否和系统userId一致;若不一致,检查系统应用或子系统进程 1. 检查当前`userId`是否和系统`userId`一致
2. 检查当前应用是否为系统应用或系统服务。
## 1500007 IPC请求发送失败 ## 1500007 IPC请求发送失败
**错误信息** **错误信息**
message send error message send error
**错误描述** **错误描述**
IPC发送请求失败。 `IPC`发送请求失败。
**可能原因** **可能原因**
没有成功创建连接对象。 没有成功创建连接对象。
......
...@@ -8,11 +8,11 @@ Internal Error. ...@@ -8,11 +8,11 @@ Internal Error.
**错误描述** **错误描述**
内存申请、多线程处理异常等内部处理错误,系统会报此错误码。 发生内存申请失败、多线程处理失败等异常时,系统会报此错误码。
**可能原因** **可能原因**
1. 内存申请、多线程处理等内核通用错误。 1. 内存申请失败、多线程处理失败等内核通用错误。
**处理步骤** **处理步骤**
...@@ -36,8 +36,9 @@ IPC Error. ...@@ -36,8 +36,9 @@ IPC Error.
**处理步骤** **处理步骤**
1. 确认参入参数是否超长。 1. 确认输入参数是否超长。
2. 确认通知子系统是否启动中。 2. 确认输入参数是否合法。
3. 确认通知子系统是否已启动。
## 1600003 连接服务错误 ## 1600003 连接服务错误
...@@ -47,7 +48,7 @@ Failed to connect to service. ...@@ -47,7 +48,7 @@ Failed to connect to service.
**错误描述** **错误描述**
当连接服务失败使通知子系统异常时,系统会报此错误码。 当连接服务失败而导致通知子系统异常时,系统会报此错误码。
**可能原因** **可能原因**
...@@ -55,8 +56,8 @@ Failed to connect to service. ...@@ -55,8 +56,8 @@ Failed to connect to service.
**处理步骤** **处理步骤**
1. 服务繁忙,请稍后重试。 1. 服务繁忙时,需要再次尝试。
2. 确认通知子系统是否启动。 2. 确认通知子系统是否正常启动。
## 1600004 通知使能未开启 ## 1600004 通知使能未开启
...@@ -70,7 +71,7 @@ Notification is not enabled. ...@@ -70,7 +71,7 @@ Notification is not enabled.
**可能原因** **可能原因**
1. 应用的通知使能是初始的未开启状态或者被用户关闭。 1. 应用的通知使能是未开启状态或者被用户手动关闭。
**处理步骤** **处理步骤**
...@@ -102,17 +103,17 @@ Notification is not allowed to remove. ...@@ -102,17 +103,17 @@ Notification is not allowed to remove.
**错误描述** **错误描述**
当通知设置isUnremoveable=true标识时全清,当设置isRemoveAllowed=false时,删除时,系统会报此错误码 删除通知时不具有相应的权限
**可能原因** **可能原因**
1. 通知上设置了isUnremoveable=true标识,不允许全清只允许单条删除 1. 通知设置`isUnremovable``true`,只允许删除单条通知,而不允许删除全部通知
2. 通知上设置了isRemoveAllowed=false,不允许删除 2. 通知设置`isRemoveAllowed``false`,不允许删除通知
**处理步骤** **处理步骤**
1. 检查通知是否设置了unremovable=true标识 1. 检查通知是否设置了`isUnremovable``true`
2. 检查通知是否设置了isRemoveAllowed=false标识 2. 检查通知是否设置了`isRemoveAllowed``false`
## 1600007 通知不存在 ## 1600007 通知不存在
...@@ -122,7 +123,7 @@ The notification is not exist. ...@@ -122,7 +123,7 @@ The notification is not exist.
**错误描述** **错误描述**
当通知被删除或取消,不存在时,系统会报此错误码。 当通知不存在时,系统会报此错误码。
**可能原因** **可能原因**
...@@ -141,7 +142,7 @@ The user is not exist. ...@@ -141,7 +142,7 @@ The user is not exist.
**错误描述** **错误描述**
当用户ID错误,或设备用户未激活时,系统会报此错误码。 当用户ID错误,或设备用户未激活时,系统会报此错误码。
**可能原因** **可能原因**
...@@ -206,8 +207,8 @@ Read template config failed. ...@@ -206,8 +207,8 @@ Read template config failed.
**处理步骤** **处理步骤**
1. 检查系统/system/etc/notification_template/external.json文件是否存在。 1. 检查系统`/system/etc/notification_template/external.json`文件是否存在。
2. 升级版本到3.2及以上。 2. 升级系统版本到3.2及以上。
## 17700001 包名不存在 ## 17700001 包名不存在
......
...@@ -8,16 +8,16 @@ Notification is not enabled. ...@@ -8,16 +8,16 @@ Notification is not enabled.
**错误描述** **错误描述**
当调用发布提醒接口时,允许应用发送通知。 当调用发布提醒接口时,允许应用发送通知。
**可能原因** **可能原因**
1. 未申请通知使能。 1. 未申请通知使能权限
2. 通知使能被关闭。 2. 通知使能被关闭。
**处理步骤** **处理步骤**
1. 申请通知使能弹窗[Notification.requestEnableNotification](../apis/js-apis-notification.md#notificationrequestenablenotification8) 1. 申请通知使能权限弹窗[Notification.requestEnableNotification](../apis/js-apis-notification.md#notificationrequestenablenotification8)
2. 检查通知使能是否被关闭。 2. 检查通知使能是否被关闭。
## 1700002 提醒数量超出限制 ## 1700002 提醒数量超出限制
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册