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

!10699 提醒代理错误码整改

Merge pull request !10699 from 廖康康/master
......@@ -63,7 +63,6 @@
- [@ohos.commonEvent (公共事件模块)](js-apis-commonEvent.md)
- [@ohos.events.emitter (Emitter)](js-apis-emitter.md)
- [@ohos.notification (Notification模块)](js-apis-notification.md)
- [@ohos.reminderAgent (后台代理提醒)](js-apis-reminderAgent.md)
- application/[EventHub (EventHub)](js-apis-eventhub.md)
- 应用程序包管理
- [@ohos.bundle (Bundle模块)](js-apis-Bundle.md)
......@@ -120,6 +119,7 @@
- 资源调度
- [@ohos.backgroundTaskManager (后台任务管理)](js-apis-backgroundTaskManager.md)
- [@ohos.distributedMissionManager (分布式任务管理)](js-apis-distributedMissionManager.md)
- [@ohos.reminderAgentManager (后台代理提醒)](js-apis-reminderAgentManager.md)
- [@ohos.workScheduler (延迟任务调度)](js-apis-workScheduler.md)
- [@ohos.WorkSchedulerExtensionAbility (延迟任务调度回调)](js-apis-WorkSchedulerExtensionAbility.md)
- 定制管理
......@@ -271,6 +271,7 @@
- [@ohos.bytrace (性能打点)](js-apis-bytrace.md)
- [@ohos.data.storage (轻量级存储)](js-apis-data-storage.md)
- [@ohos.prompt (弹窗)](js-apis-prompt.md)
- [@ohos.reminderAgent (后台代理提醒)](js-apis-reminderAgent.md)
- [@system.app (应用上下文)](js-apis-system-app.md)
- [@system.battery (电量信息)](js-apis-system-battery.md)
- [@system.bluetooth (蓝牙)](js-apis-system-bluetooth.md)
......
......@@ -4,7 +4,10 @@
开发应用时,开发者可以调用后台提醒发布的接口创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> **说明:**
>
> 从API Version 9 开始,该接口不再维护,推荐使用新接口[@ohos.reminderAgentManager (后台代理提醒)](js-apis-reminderAgentManager.md)
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
......
# 后台代理提醒
本模块提供后台代理提醒的能力。
开发应用时,开发者可以调用后台提醒发布的接口创建定时提醒,包括倒计时、日历、闹钟三种提醒类型。使用后台代理提醒能力后,应用可以被冻结或退出,计时和弹出提醒的功能将被后台系统服务代理。
> **说明:**
>
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```
import reminderAgentManager from'@ohos.reminderAgentManager';
```
## reminderAgentManager.publishReminder
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void
发布一个后台代理提醒,使用callback方式实现异步调用,该方法需要申请通知弹窗[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。
**需要权限**: ohos.permission.PUBLISH_AGENT_REMINDER
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 |
| callback | AsyncCallback<number> | 是 | 异步回调,返回当前发布的提醒的reminderId。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700001 | Notification does not enable. |
| 1700002 | The number of reminders exceeds the limit. |
**示例**
```js
let timer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10
}
try {
reminderAgentManager.publishReminder(timer, (err, reminderId) => {
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("callback, reminderId = " + reminderId);
}
});
} catch (error) {
console.log("publishReminder code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.publishReminder
publishReminder(reminderReq: ReminderRequest): Promise<number>
发布一个后台代理提醒,使用Promise方式实现异步调用,该方法需要申请通知弹窗[Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8)后才能调用。
**需要权限**: ohos.permission.PUBLISH_AGENT_REMINDER
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reminderReq | [ReminderRequest](#reminderrequest) | 是 | 需要发布的提醒实例。 |
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise<number> | 返回提醒的reminderId。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700001 | Notification does not enable. |
| 1700002 | The number of reminders exceeds the limit. |
**示例**
```js
let timer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10
}
try {
reminderAgentManager.publishReminder(timer).then((reminderId) => {
console.log("promise, reminderId = " + reminderId);
}).catch(err => {
console.log("promise err code:" + err.code + " message:" + err.message);
});
} catch (error) {
console.log("publishReminder code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.cancelReminder
cancelReminder(reminderId: number, callback: AsyncCallback<void>): void
取消指定id的提醒,使用callback方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reminderId | number | 是 | 目标reminder的id号。 |
| callback | AsyncCallback<void> | 是 | 异步回调。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700003 | The reminder does not exist. |
| 1700004 | The package name does not exist. |
**示例**
```js
try {
reminderAgentManager.cancelReminder(1, (err, data) => {
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("cancelReminder callback");
}
});
} catch (error) {
console.log("cancelReminder code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.cancelReminder
cancelReminder(reminderId: number): Promise<void>
取消指定id的提醒,使用Promise方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reminderId | number | 是 | 目标reminder的id号。 |
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise<void> | Promise类型异步回调。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700003 | The reminder does not exist. |
| 1700004 | The package name does not exist. |
**示例**
```js
try {
reminderAgentManager.cancelReminder(1).then(() => {
console.log("cancelReminder promise");
}).catch(err => {
console.log("promise err code:" + err.code + " message:" + err.message);
});
} catch (error) {
console.log("cancelReminder code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.getValidReminders
getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void
获取当前应用已设置的所有有效(未过期)的提醒,使用callback方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<Array<[ReminderRequest](#reminderrequest)>> | 是 | 异步回调,返回当前应用已设置的所有有效(未过期)的提醒。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700004 | The package name does not exist. |
**示例**
```js
try {
reminderAgentManager.getValidReminders((err, reminders) => {
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("callback, getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) {
console.log("getValidReminders = " + reminders[i]);
console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
for (let j = 0; j < reminders[i].actionButton.length; j++) {
console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title);
console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type);
}
console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName);
console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName);
console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName);
console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName);
console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration);
console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes);
console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval);
console.log("getValidReminders, title = " + reminders[i].title);
console.log("getValidReminders, content = " + reminders[i].content);
console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent);
console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent);
console.log("getValidReminders, notificationId = " + reminders[i].notificationId);
console.log("getValidReminders, slotType = " + reminders[i].slotType);
}
}
})
} catch (error) {
console.log("getValidReminders code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.getValidReminders
getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt;
获取当前应用已设置的所有有效(未过期)的提醒,使用Promise方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;Array&lt;[ReminderRequest](#reminderrequest)&gt;&gt; | 返回当前应用已设置的所有有效(未过期)的提醒。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700004 | The package name does not exist. |
**示例**
```js
try {
reminderAgentManager.getValidReminders().then((reminders) => {
console.log("promise, getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) {
console.log("getValidReminders = " + reminders[i]);
console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
for (let j = 0; j < reminders[i].actionButton.length; j++) {
console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title);
console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type);
}
console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName);
console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName);
console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName);
console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName);
console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration);
console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes);
console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval);
console.log("getValidReminders, title = " + reminders[i].title);
console.log("getValidReminders, content = " + reminders[i].content);
console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent);
console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent);
console.log("getValidReminders, notificationId = " + reminders[i].notificationId);
console.log("getValidReminders, slotType = " + reminders[i].slotType);
}
}).catch(err => {
console.log("promise err code:" + err.code + " message:" + err.message);
});
} catch (error) {
console.log("getValidReminders code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.cancelAllReminders
cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void
取消当前应用所有的提醒,使用callback方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700004 | The package name does not exist. |
**示例**
```js
try {
reminderAgentManager.cancelAllReminders((err, data) =>{
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("cancelAllReminders callback")
}
})
} catch (error) {
console.log("cancelAllReminders code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.cancelAllReminders
cancelAllReminders(): Promise&lt;void&gt;
取消当前应用所有的提醒,使用Promise方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 |
**错误码:**
以下错误码的详细介绍请参见[@ohos.reminderAgentManager (后台代理提醒)](../errorcodes/errcode-reminderAgentManager.md)错误码。
| 错误码ID | 错误码信息 |
| --------- | ------- |
| 1700004 | The package name does not exist. |
**示例**
```js
try {
reminderAgentManager.cancelAllReminders().then(() => {
console.log("cancelAllReminders promise")
}).catch(err => {
console.log("promise err code:" + err.code + " message:" + err.message);
});
} catch (error) {
console.log("cancelAllReminders code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.addNotificationSlot
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;): void
添加一个NotificationSlot,使用callback方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification&nbsp;slot实例,仅支持设置其type属性。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 |
**示例**
```js
import notification from '@ohos.notification'
let mySlot = {
type: notification.SlotType.SOCIAL_COMMUNICATION
}
try {
reminderAgentManager.addNotificationSlot(mySlot, (err, data) => {
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("addNotificationSlot callback");
}
});
} catch (error) {
console.log("addNotificationSlot code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.addNotificationSlot
addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt;
添加一个NotificationSlot,使用Promise方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | 是 | notification&nbsp;slot实例,仅支持设置其type属性。 |
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 |
**示例**
```js
import notification from '@ohos.notification'
let mySlot = {
type: notification.SlotType.SOCIAL_COMMUNICATION
}
try {
reminderAgentManager.addNotificationSlot(mySlot).then(() => {
console.log("addNotificationSlot promise");
}).catch(err => {
console.log("promise err code:" + err.code + " message:" + err.message);
});
} catch (error) {
console.log("addNotificationSlot code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback&lt;void&gt;): void
删除目标NotificationSlot,使用callback方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification&nbsp;slot的类型。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步回调。 |
**示例**
```js
import notification from '@ohos.notification'
try {
reminderAgentManager.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => {
if (err) {
console.log("callback err code:" + err.code + " message:" + err.message);
} else {
console.log("removeNotificationSlot callback");
}
});
} catch (error) {
console.log("removeNotificationSlot code:" + error.code + " message:" + error.message);
};
```
## reminderAgentManager.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt;
删除目标NotificationSlot,使用Promise方式实现异步调用。
**系统能力**: SystemCapability.Notification.ReminderAgent
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 是 | 目标notification&nbsp;slot的类型。 |
**返回值**
| 类型 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | Promise类型异步回调。 |
**示例**
```js
import notification from '@ohos.notification'
try {
reminderAgentManager.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => {
console.log("removeNotificationSlot promise");
}).catch(err => {
console.log("promise err code:" + err.code + " message:" + err.message);
});
} catch (error) {
console.log("removeNotificationSlot code:" + error.code + " message:" + error.message);
};
```
## ActionButtonType
按钮的类型。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| ACTION_BUTTON_TYPE_CLOSE | 0 | 表示关闭提醒的按钮。 |
| ACTION_BUTTON_TYPE_SNOOZE | 1 | 表示延迟提醒的按钮。 |
## ReminderType
提醒的类型。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| REMINDER_TYPE_TIMER | 0 | 表示提醒类型:倒计时。 |
| REMINDER_TYPE_CALENDAR | 1 | 表示提醒类型:日历。 |
| REMINDER_TYPE_ALARM | 2 | 表示提醒类型:闹钟。 |
## ActionButton
用于设置弹出的提醒通知信息上显示的按钮类型和标题。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| title | string | 是 | 按钮显示的标题。 |
| type | [ActionButtonType](#actionbuttontype) | 是 | 按钮的类型。 |
## WantAgent
点击提醒通知后跳转的目标ability信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| pkgName | string | 是 | 指明点击提醒通知栏后跳转的目标hap包名。 |
| abilityName | string | 是 | 指明点击提醒通知栏后跳转的目标ability名称。 |
## MaxScreenWantAgent
全屏显示提醒到达时自动拉起的目标ability信息,该接口预留。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| pkgName | string | 是 | 指明提醒到达时自动拉起的目标hap包名(如果设备在使用中,则只弹出通知横幅框)。 |
| abilityName | string | 是 | 指明提醒到达时自动拉起的目标ability名(如果设备在使用中,则只弹出通知横幅框)。 |
## ReminderRequest
提醒实例对象,用于设置提醒类型、响铃时长等具体信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reminderType | ReminderType | 是 | 指明提醒类型。 |
| actionButton | [ActionButton?,&nbsp;ActionButton?] | 否 | 弹出的提醒通知栏中显示的按钮(参数可选,支持0/1/2个按钮)。 |
| wantAgent | WantAgent | 否 | 点击通知后需要跳转的目标ability信息。 |
| maxScreenWantAgent | MaxScreenWantAgent | 否 | 提醒到达时跳转的目标包。如果设备正在使用中,则弹出一个通知框。 |
| ringDuration | number | 否 | 指明响铃时长。 |
| snoozeTimes | number | 否 | 指明延迟提醒次数。 |
| timeInterval | number | 否 | 执行延迟提醒间隔。 |
| title | string | 否 | 指明提醒标题。 |
| content | string | 否 | 指明提醒内容。 |
| expiredContent | string | 否 | 指明提醒过期后需要显示的内容。 |
| snoozeContent | string | 否 | 指明延迟提醒时需要显示的内容。 |
| notificationId | number | 否 | 指明提醒使用的通知的id号,相同id号的提醒会覆盖。 |
| slotType | [notification.SlotType](js-apis-notification.md#slottype) | 否 | 指明提醒的slot类型。 |
## ReminderRequestCalendar
ReminderRequestCalendar extends ReminderRequest
日历实例对象,用于设置提醒的时间。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| dateTime | [LocalDateTime](#localdatetime) | 是 | 指明提醒的目标时间。 |
| repeatMonths | Array&lt;number&gt; | 否 | 指明重复提醒的月份。 |
| repeatDays | Array&lt;number&gt; | 否 | 指明重复提醒的日期。 |
## ReminderRequestAlarm
ReminderRequestAlarm extends ReminderRequest
闹钟实例对象,用于设置提醒的时间。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| hour | number | 是 | 指明提醒的目标时刻。 |
| minute | number | 是 | 指明提醒的目标分钟。 |
| daysOfWeek | Array&lt;number&gt; | 否 | 指明每周哪几天需要重复提醒。 |
## ReminderRequestTimer
ReminderRequestTimer extends ReminderRequest
倒计时实例对象,用于设置提醒的时间。
**系统能力**:SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| triggerTimeInSeconds | number | 是 | 指明倒计时的秒数。 |
## LocalDateTime
用于日历类提醒设置时指定时间信息。
**系统能力**:以下各项对应的系统能力均为SystemCapability.Notification.ReminderAgent
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| year | number | 是 | 年 |
| month | number | 是 | 月 |
| day | number | 是 | 日 |
| hour | number | 是 | 时 |
| minute | number | 是 | 分 |
| second | number | 否 | 秒 |
# reminderAgentManager错误码
## 1700001 通知使能未开启
**错误信息**
Notification does not enable.
**错误描述**
当调用发布提醒接口时,未允许应用发送通知。
**可能原因**
1. 未申请通知使能。
2. 通知使能被关闭。
**处理步骤**
1. 申请通知使能弹窗[Notification.requestEnableNotification](../apis/js-apis-notification.md#notificationrequestenablenotification8)
2. 检查通知使能是否被关闭。
## 1700002 提醒数量超出限制
**错误信息**
The number of reminders exceeds the limit.
**错误描述**
当调用发布提醒接口时,提醒数量超出最大限制。
**可能原因**
1. 当前系统提醒超过2000个。
2. 当前应用提醒超过30个。
**处理步骤**
删除不必要的提醒。
## 1700003 提醒不存在
**错误信息**
The reminder does not exist.
**错误描述**
当调用取消提醒接口时,未找到对应的提醒。
**可能原因**
1. 提醒已过期。
2. 提醒已被删除。
**处理步骤**
1. 检查提醒是否有效。
2. 检查提醒是否已被删除。
## 1700004 包名不存在
**错误信息**
The package name does not exist.
**错误描述**
未找到传入的包名信息。
**可能原因**
1. 包名不正确。
2. 应用未安装。
**处理步骤**
检查应用包名是否存在。
......@@ -7,11 +7,11 @@
## 接口说明
reminderAgent:封装了发布、取消提醒类通知的方法。
reminderAgentManager:封装了发布、取消提醒类通知的方法。
具体后台提醒相关功能接口请见[后台代理提醒](../reference/apis/js-apis-reminderAgent.md)
具体后台提醒相关功能接口请见[后台代理提醒](../reference/apis/js-apis-reminderAgentManager.md)
**表1** reminderAgent主要接口
**表1** reminderAgentManager主要接口
| 接口名 | 描述 |
| -------- | -------- |
......@@ -36,17 +36,17 @@ reminderAgent:封装了发布、取消提醒类通知的方法。
2、发布相应的提醒代理。
```ts
import reminderAgent from '@ohos.reminderAgent';
import reminderAgentManager from '@ohos.reminderAgentManager';
import notification from '@ohos.notification';
// 倒计时实例定义:
let timer : reminderAgent.ReminderRequestTimer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
let timer : reminderAgentManager.ReminderRequestTimer = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10,
actionButton: [
{
title: "close",
type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE
type: reminderAgentManager.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE
}
],
wantAgent: {
......@@ -65,8 +65,8 @@ let timer : reminderAgent.ReminderRequestTimer = {
}
// 日历实例定义:
let calendar : reminderAgent.ReminderRequestCalendar = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR,
let calendar : reminderAgentManager.ReminderRequestCalendar = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_CALENDAR,
dateTime: {
year: 2050,
month: 7,
......@@ -80,11 +80,11 @@ let calendar : reminderAgent.ReminderRequestCalendar = {
actionButton: [
{
title: "close",
type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE
type: reminderAgentManager.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE
},
{
title: "snooze",
type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE
type: reminderAgentManager.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE
},
],
wantAgent: {
......@@ -107,19 +107,19 @@ let calendar : reminderAgent.ReminderRequestCalendar = {
}
// 闹钟实例定义:
let alarm : reminderAgent.ReminderRequestAlarm = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM,
let alarm : reminderAgentManager.ReminderRequestAlarm = {
reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_ALARM,
hour: 11,
minute: 14,
daysOfWeek: [0],
actionButton: [
{
title: "close",
type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE
type: reminderAgentManager.ActionButtonType.ACTION_BUTTON_TYPE_CLOSE
},
{
title: "snooze",
type: reminderAgent.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE
type: reminderAgentManager.ActionButtonType.ACTION_BUTTON_TYPE_SNOOZE
},
],
wantAgent: {
......@@ -147,9 +147,15 @@ struct Index {
@State message: string = 'test'
publishReminder() {
reminderAgent.publishReminder(timer, (err, reminderId) => {
console.log("callback, reminderId = " + reminderId);
});
try {
reminderAgentManager.publishReminder(timer).then(res => {
console.log("publishReminder promise reminderId:" + res);
}).catch(err => {
console.log("publishReminder err code:" + err.code + " message:" + err.message);
})
} catch (error) {
console.log("publishReminder code:" + error.code + " message:" + error.message);
};
}
build() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册