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

!3266 后台代理提醒-更新开发指南描述和接口文档示例

Merge pull request !3266 from rcy-hw/0326
...@@ -350,7 +350,7 @@ You can set your application to call the **ReminderRequest** class to create s ...@@ -350,7 +350,7 @@ You can set your application to call the **ReminderRequest** class to create s
**ReminderRequestCalendar** extends **ReminderRequest** and defines a reminder for a calendar event. **ReminderRequestCalendar** extends **ReminderRequest** and defines a reminder for a calendar event.
For the application to run properly, if both **repeatMonths** and **repeatDays** are not specified, the earliest reminder time must be later than the current time. For the application to run properly, if both **repeatMonths** and **repeatDays** are not specified, the earliest reminder time must be later than the current time.
**Table 8** ReminderRequestCalendar instance **Table 8** ReminderRequestCalendar instance
...@@ -542,7 +542,7 @@ For the application to run properly, if both **repeatMonths** and **repeatDays** ...@@ -542,7 +542,7 @@ For the application to run properly, if both **repeatMonths** and **repeatDays**
## How to Develop<a name="section4207112818418"></a> ## How to Develop<a name="section4207112818418"></a>
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE:**
>To publish a reminder, your application needs to apply for the **ohos.permission.PUBLISH\_AGENT\_REMINDER** permission. >To publish a reminder, your application needs to apply for the **ohos.permission.PUBLISH\_AGENT\_REMINDER** permission.
Publish a 10-second countdown reminder. Publish a 10-second countdown reminder.
...@@ -553,7 +553,10 @@ Publish a 10-second countdown reminder. ...@@ -553,7 +553,10 @@ Publish a 10-second countdown reminder.
import reminderAgent from '@ohos.reminderAgent'; import reminderAgent from '@ohos.reminderAgent';
import notification from '@ohos.notification'; import notification from '@ohos.notification';
export default { export default {
timer: { // In JS Project:
// timer: {
// In eTS Project:
let timer : reminderAgent.ReminderRequestTimer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10, triggerTimeInSeconds: 10,
actionButton: [ actionButton: [
...@@ -602,7 +605,10 @@ Publish a 10-second countdown reminder. ...@@ -602,7 +605,10 @@ Publish a 10-second countdown reminder.
Sample code for defining a calendar reminder instance: Sample code for defining a calendar reminder instance:
``` ```
calendar: { // In JS Project:
// calendar: {
// In eTS Project:
let calendar : reminderAgent.ReminderRequestCalendar = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR,
dateTime: { dateTime: {
year: 2050, year: 2050,
...@@ -647,7 +653,10 @@ calendar: { ...@@ -647,7 +653,10 @@ calendar: {
Sample code for defining an alarm reminder instance: Sample code for defining an alarm reminder instance:
``` ```
alarm: { // In JS Project:
// alarm: {
// In eTS Project:
let alarm : reminderAgent.ReminderRequestAlarm = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM,
hour: 11, hour: 11,
minute: 14, minute: 14,
......
...@@ -29,19 +29,14 @@ Publishes an agent-powered reminder. This API uses an asynchronous callback to r ...@@ -29,19 +29,14 @@ Publishes an agent-powered reminder. This API uses an asynchronous callback to r
| callback | AsyncCallback&lt;number&gt; | Yes| Asynchronous callback used to return the published reminder's ID.| | callback | AsyncCallback&lt;number&gt; | Yes| Asynchronous callback used to return the published reminder's ID.|
**Example** **Example**
``` ```js
export default { let timer = {
data: { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
timer: { triggerTimeInSeconds: 10
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 3
}
},
startTimer() {
reminderAgent.publishReminder(timer, (err, reminderId) => { console.log("reminderId = " + reminderId);
});
}
} }
reminderAgent.publishReminder(timer, (err, reminderId) => {
console.log("reminderId = " + reminderId);
});
``` ```
...@@ -64,20 +59,14 @@ Publishes an agent-powered reminder. This API uses a promise callback to return ...@@ -64,20 +59,14 @@ Publishes an agent-powered reminder. This API uses a promise callback to return
| Promise&lt;number&gt; | Promise used to return the published reminder's ID.| | Promise&lt;number&gt; | Promise used to return the published reminder's ID.|
**Example** **Example**
``` ```js
export default { let timer = {
data: reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
{timer: { triggerTimeInSeconds: 10
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 3
}
},
startTimer() {
reminderAgent.publishReminder(this.timer).then((reminderId) => {
console.log("reminderId = " + reminderId);
});
}
} }
reminderAgent.publishReminder(timer).then((reminderId) => {
console.log("reminderId = " + reminderId);
});
``` ```
...@@ -98,14 +87,10 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba ...@@ -98,14 +87,10 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba
**Example** **Example**
``` ```js
export default { reminderAgent.cancelReminder(1, (err, data) => {
cancel() { console.log("cancelReminder callback");
reminderAgent.cancelReminder(1, (err, data) => { });
console.log("do next");
});
}
}
``` ```
...@@ -131,14 +116,10 @@ Cancels the reminder with the specified ID. This API uses a promise to return th ...@@ -131,14 +116,10 @@ Cancels the reminder with the specified ID. This API uses a promise to return th
**Example** **Example**
``` ```js
export default { reminderAgent.cancelReminder(1).then(() => {
cancel() { console.log("cancelReminder promise");
reminderAgent.cancelReminder(1).then(() => { });
console.log("do next");
});
}
}
``` ```
...@@ -158,8 +139,9 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -158,8 +139,9 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
**Example** **Example**
``` ```js
reminderAgent.getValidReminders((err, reminders) => { reminderAgent.getValidReminders((err, reminders) => {
console.log("getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) { for (let i = 0; i < reminders.length; i++) {
console.log("getValidReminders = " + reminders[i]); console.log("getValidReminders = " + reminders[i]);
console.log("getValidReminders, reminderType = " + reminders[i].reminderType); console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
...@@ -201,8 +183,9 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -201,8 +183,9 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
**Example** **Example**
``` ```js
reminderAgent.getValidReminders().then((reminders) => { reminderAgent.getValidReminders().then((reminders) => {
console.log("getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) { for (let i = 0; i < reminders.length; i++) {
console.log("getValidReminders = " + reminders[i]); console.log("getValidReminders = " + reminders[i]);
console.log("getValidReminders, reminderType = " + reminders[i].reminderType); console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
...@@ -244,9 +227,10 @@ Cancels all reminders set by the current application. This API uses an asynchron ...@@ -244,9 +227,10 @@ Cancels all reminders set by the current application. This API uses an asynchron
**Example** **Example**
``` ```js
reminderAgent.cancelAllReminders((err, data) =>{ reminderAgent.cancelAllReminders((err, data) =>{
console.log("do next")}) console.log("cancelAllReminders callback")
})
``` ```
...@@ -266,9 +250,10 @@ Cancels all reminders set by the current application. This API uses a promise to ...@@ -266,9 +250,10 @@ Cancels all reminders set by the current application. This API uses a promise to
**Example** **Example**
``` ```js
reminderAgent.cancelAllReminders().then(() => { reminderAgent.cancelAllReminders().then(() => {
console.log("do next")}) console.log("cancelAllReminders promise")
})
``` ```
...@@ -289,17 +274,14 @@ Adds a reminder notification slot. This API uses an asynchronous callback to ret ...@@ -289,17 +274,14 @@ Adds a reminder notification slot. This API uses an asynchronous callback to ret
**Example** **Example**
``` ```js
export default { data: { mySlot: { let mySlot = {
type: 3, type: 3,
sound: "/sdcard/music2.mp3" sound: "/sdcard/music2.mp3"
} },
addSlot() {
reminderAgent.addNotificationSlot(this.mySlot, (err, data) => {
console.log("do next");
});
}
} }
reminderAgent.addNotificationSlot(mySlot, (err, data) => {
console.log("addNotificationSlot callback");
});
``` ```
...@@ -325,17 +307,14 @@ Adds a reminder notification slot. This API uses a promise to return the result. ...@@ -325,17 +307,14 @@ Adds a reminder notification slot. This API uses a promise to return the result.
**Example** **Example**
``` ```js
export default { data: { mySlot: { let mySlot = {
type: 3, type: 3,
sound: "/sdcard/music2.mp3" sound: "/sdcard/music2.mp3"
} },
addSlot() {
reminderAgent.addNotificationSlot(this.mySlot).then(() => {
console.log("do next");
});
}
} }
reminderAgent.addNotificationSlot(mySlot).then(() => {
console.log("addNotificationSlot promise");
});
``` ```
...@@ -356,13 +335,10 @@ Removes a notification slot of a specified type. This API uses an asynchronous c ...@@ -356,13 +335,10 @@ Removes a notification slot of a specified type. This API uses an asynchronous c
**Example** **Example**
``` ```js
export default { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => {
removeSlot() {reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => { console.log("removeNotificationSlot callback");
console.log("do next");
}); });
}
}
``` ```
...@@ -388,13 +364,10 @@ Removes a notification slot of a specified type. This API uses a promise to retu ...@@ -388,13 +364,10 @@ Removes a notification slot of a specified type. This API uses a promise to retu
**Example** **Example**
``` ```js
export default { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => {
removeSlot() { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => { console.log("removeNotificationSlot promise");
console.log("do next"); });
});
}
}
``` ```
......
...@@ -139,8 +139,12 @@ interface LocalDateTime:时间信息实例 ...@@ -139,8 +139,12 @@ interface LocalDateTime:时间信息实例
1. 定义一个倒计时实例 1. 定义一个倒计时实例
``` ```
import reminderAgent from '@ohos.reminderAgent'; import reminderAgent from '@ohos.reminderAgent';
import notification from '@ohos.notification';export default { import notification from '@ohos.notification';
timer: { export default {
// JS工程写法:
// timer: {
// eTS工程写法:
let timer : reminderAgent.ReminderRequestTimer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10, triggerTimeInSeconds: 10,
actionButton: [ actionButton: [
...@@ -186,7 +190,10 @@ interface LocalDateTime:时间信息实例 ...@@ -186,7 +190,10 @@ interface LocalDateTime:时间信息实例
日历实例定义: 日历实例定义:
``` ```
calendar: { // JS工程写法:
// calendar: {
// eTS工程写法:
let calendar : reminderAgent.ReminderRequestCalendar = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_CALENDAR,
dateTime: { dateTime: {
year: 2050, year: 2050,
...@@ -231,7 +238,10 @@ calendar: { ...@@ -231,7 +238,10 @@ calendar: {
闹钟实例定义: 闹钟实例定义:
``` ```
alarm: { // JS工程写法:
// alarm: {
// eTS工程写法:
let alarm : reminderAgent.ReminderRequestAlarm = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM, reminderType: reminderAgent.ReminderType.REMINDER_TYPE_ALARM,
hour: 11, hour: 11,
minute: 14, minute: 14,
......
...@@ -29,20 +29,15 @@ publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number& ...@@ -29,20 +29,15 @@ publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback&lt;number&
| callback | AsyncCallback&lt;number&gt; | 是 | 异步回调,返回当前发布的提醒的reminderId。 | | callback | AsyncCallback&lt;number&gt; | 是 | 异步回调,返回当前发布的提醒的reminderId。 |
**示例** **示例**
``` ```js
export default { let timer = {
data: { reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
timer: { triggerTimeInSeconds: 10
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 3
}
},
startTimer() {
reminderAgent.publishReminder(timer, (err, reminderId) => { console.log("reminderId = " + reminderId);
});
}
} }
``` reminderAgent.publishReminder(timer, (err, reminderId) => {
console.log("reminderId = " + reminderId);
});
```
## reminderAgent.publishReminder ## reminderAgent.publishReminder
...@@ -64,21 +59,15 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt; ...@@ -64,21 +59,15 @@ publishReminder(reminderReq: ReminderRequest): Promise&lt;number&gt;
| Promise&lt;number&gt; | 返回提醒的reminderId。 | | Promise&lt;number&gt; | 返回提醒的reminderId。 |
**示例** **示例**
``` ```js
export default { let timer = {
data: reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
{timer: { triggerTimeInSeconds: 10
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 3
}
},
startTimer() {
reminderAgent.publishReminder(this.timer).then((reminderId) => {
console.log("reminderId = " + reminderId);
});
}
} }
``` reminderAgent.publishReminder(timer).then((reminderId) => {
console.log("reminderId = " + reminderId);
});
```
## reminderAgent.cancelReminder ## reminderAgent.cancelReminder
...@@ -98,14 +87,10 @@ cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -98,14 +87,10 @@ cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
``` ```js
export default { reminderAgent.cancelReminder(1, (err, data) => {
cancel() { console.log("cancelReminder callback");
reminderAgent.cancelReminder(1, (err, data) => { });
console.log("do next");
});
}
}
``` ```
...@@ -131,14 +116,10 @@ cancelReminder(reminderId: number): Promise&lt;void&gt; ...@@ -131,14 +116,10 @@ cancelReminder(reminderId: number): Promise&lt;void&gt;
**示例** **示例**
``` ```js
export default { reminderAgent.cancelReminder(1).then(() => {
cancel() { console.log("cancelReminder promise");
reminderAgent.cancelReminder(1).then(() => { });
console.log("do next");
});
}
}
``` ```
...@@ -158,8 +139,9 @@ getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;): ...@@ -158,8 +139,9 @@ getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;):
**示例** **示例**
``` ```js
reminderAgent.getValidReminders((err, reminders) => { reminderAgent.getValidReminders((err, reminders) => {
console.log("getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) { for (let i = 0; i < reminders.length; i++) {
console.log("getValidReminders = " + reminders[i]); console.log("getValidReminders = " + reminders[i]);
console.log("getValidReminders, reminderType = " + reminders[i].reminderType); console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
...@@ -201,8 +183,9 @@ getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt; ...@@ -201,8 +183,9 @@ getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt;
**示例** **示例**
``` ```js
reminderAgent.getValidReminders().then((reminders) => { reminderAgent.getValidReminders().then((reminders) => {
console.log("getValidReminders length = " + reminders.length);
for (let i = 0; i < reminders.length; i++) { for (let i = 0; i < reminders.length; i++) {
console.log("getValidReminders = " + reminders[i]); console.log("getValidReminders = " + reminders[i]);
console.log("getValidReminders, reminderType = " + reminders[i].reminderType); console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
...@@ -244,9 +227,10 @@ cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void ...@@ -244,9 +227,10 @@ cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
``` ```js
reminderAgent.cancelAllReminders((err, data) =>{ reminderAgent.cancelAllReminders((err, data) =>{
console.log("do next")}) console.log("cancelAllReminders callback")
})
``` ```
...@@ -266,9 +250,10 @@ cancelAllReminders(): Promise&lt;void&gt; ...@@ -266,9 +250,10 @@ cancelAllReminders(): Promise&lt;void&gt;
**示例** **示例**
``` ```js
reminderAgent.cancelAllReminders().then(() => { reminderAgent.cancelAllReminders().then(() => {
console.log("do next")}) console.log("cancelAllReminders promise")
})
``` ```
...@@ -289,17 +274,14 @@ addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;) ...@@ -289,17 +274,14 @@ addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;)
**示例** **示例**
``` ```js
export default { data: { mySlot: { let mySlot = {
type: 3, type: 3,
sound: "/sdcard/music2.mp3" sound: "/sdcard/music2.mp3"
} },
addSlot() {
reminderAgent.addNotificationSlot(this.mySlot, (err, data) => {
console.log("do next");
});
}
} }
reminderAgent.addNotificationSlot(mySlot, (err, data) => {
console.log("addNotificationSlot callback");
});
``` ```
...@@ -325,17 +307,14 @@ addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt; ...@@ -325,17 +307,14 @@ addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt;
**示例** **示例**
``` ```js
export default { data: { mySlot: { let mySlot = {
type: 3, type: 3,
sound: "/sdcard/music2.mp3" sound: "/sdcard/music2.mp3"
} },
addSlot() {
reminderAgent.addNotificationSlot(this.mySlot).then(() => {
console.log("do next");
});
}
} }
reminderAgent.addNotificationSlot(mySlot).then(() => {
console.log("addNotificationSlot promise");
});
``` ```
...@@ -356,13 +335,10 @@ removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback& ...@@ -356,13 +335,10 @@ removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback&
**示例** **示例**
``` ```js
export default { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => {
removeSlot() {reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => { console.log("removeNotificationSlot callback");
console.log("do next");
}); });
}
}
``` ```
...@@ -388,13 +364,10 @@ removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt; ...@@ -388,13 +364,10 @@ removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt;
**示例** **示例**
``` ```js
export default { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => {
removeSlot() { reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => { console.log("removeNotificationSlot promise");
console.log("do next"); });
});
}
}
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册