提交 d87e6b2c 编写于 作者: R rcy-hw

update api and user guide

Signed-off-by: Nrcy-hw <renchunyang@huawei.com>
上级 d66c8408
...@@ -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,
......
...@@ -30,18 +30,13 @@ Publishes an agent-powered reminder. This API uses an asynchronous callback to r ...@@ -30,18 +30,13 @@ Publishes an agent-powered reminder. This API uses an asynchronous callback to r
**Example** **Example**
``` ```
export default { let timer : reminderAgent.ReminderRequestTimer = {
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);
});
``` ```
...@@ -65,19 +60,13 @@ Publishes an agent-powered reminder. This API uses a promise callback to return ...@@ -65,19 +60,13 @@ Publishes an agent-powered reminder. This API uses a promise callback to return
**Example** **Example**
``` ```
export default { let timer : reminderAgent.ReminderRequestTimer = {
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);
});
``` ```
...@@ -99,13 +88,9 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba ...@@ -99,13 +88,9 @@ Cancels the reminder with the specified ID. This API uses an asynchronous callba
**Example** **Example**
``` ```
export default { reminderAgent.cancelReminder(1, (err, data) => {
cancel() { console.log("cancelReminder callback");
reminderAgent.cancelReminder(1, (err, data) => { });
console.log("do next");
});
}
}
``` ```
...@@ -132,13 +117,9 @@ Cancels the reminder with the specified ID. This API uses a promise to return th ...@@ -132,13 +117,9 @@ Cancels the reminder with the specified ID. This API uses a promise to return th
**Example** **Example**
``` ```
export default { reminderAgent.cancelReminder(1).then(() => {
cancel() { console.log("cancelReminder promise");
reminderAgent.cancelReminder(1).then(() => { });
console.log("do next");
});
}
}
``` ```
...@@ -160,6 +141,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -160,6 +141,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
``` ```
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);
...@@ -203,6 +185,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th ...@@ -203,6 +185,7 @@ Obtains all valid (not yet expired) reminders set by the current application. Th
``` ```
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);
...@@ -246,7 +229,8 @@ Cancels all reminders set by the current application. This API uses an asynchron ...@@ -246,7 +229,8 @@ Cancels all reminders set by the current application. This API uses an asynchron
``` ```
reminderAgent.cancelAllReminders((err, data) =>{ reminderAgent.cancelAllReminders((err, data) =>{
console.log("do next")}) console.log("cancelAllReminders callback")
})
``` ```
...@@ -268,7 +252,8 @@ Cancels all reminders set by the current application. This API uses a promise to ...@@ -268,7 +252,8 @@ Cancels all reminders set by the current application. This API uses a promise to
``` ```
reminderAgent.cancelAllReminders().then(() => { reminderAgent.cancelAllReminders().then(() => {
console.log("do next")}) console.log("cancelAllReminders promise")
})
``` ```
...@@ -290,16 +275,13 @@ Adds a reminder notification slot. This API uses an asynchronous callback to ret ...@@ -290,16 +275,13 @@ Adds a reminder notification slot. This API uses an asynchronous callback to ret
**Example** **Example**
``` ```
export default { data: { mySlot: { 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(this.mySlot, (err, data) => {
console.log("addNotificationSlot callback");
});
``` ```
...@@ -357,12 +339,9 @@ Removes a notification slot of a specified type. This API uses an asynchronous c ...@@ -357,12 +339,9 @@ Removes a notification slot of a specified type. This API uses an asynchronous c
**Example** **Example**
``` ```
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");
}); });
}
}
``` ```
...@@ -389,12 +368,9 @@ Removes a notification slot of a specified type. This API uses a promise to retu ...@@ -389,12 +368,9 @@ Removes a notification slot of a specified type. This API uses a promise to retu
**Example** **Example**
``` ```
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。 |
**示例** **示例**
``` ```
export default { let timer : reminderAgent.ReminderRequestTimer = {
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。 |
**示例** **示例**
``` ```
export default { let timer : reminderAgent.ReminderRequestTimer = {
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
...@@ -99,13 +88,9 @@ cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void ...@@ -99,13 +88,9 @@ cancelReminder(reminderId: number, callback: AsyncCallback&lt;void&gt;): void
**示例** **示例**
``` ```
export default { reminderAgent.cancelReminder(1, (err, data) => {
cancel() { console.log("cancelReminder callback");
reminderAgent.cancelReminder(1, (err, data) => { });
console.log("do next");
});
}
}
``` ```
...@@ -132,13 +117,9 @@ cancelReminder(reminderId: number): Promise&lt;void&gt; ...@@ -132,13 +117,9 @@ cancelReminder(reminderId: number): Promise&lt;void&gt;
**示例** **示例**
``` ```
export default { reminderAgent.cancelReminder(1).then(() => {
cancel() { console.log("cancelReminder promise");
reminderAgent.cancelReminder(1).then(() => { });
console.log("do next");
});
}
}
``` ```
...@@ -160,6 +141,7 @@ getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;): ...@@ -160,6 +141,7 @@ getValidReminders(callback: AsyncCallback&lt;Array&lt;ReminderRequest&gt;&gt;):
``` ```
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);
...@@ -203,6 +185,7 @@ getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt; ...@@ -203,6 +185,7 @@ getValidReminders(): Promise&lt;Array&lt;ReminderRequest&gt;&gt;
``` ```
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);
...@@ -246,7 +229,8 @@ cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void ...@@ -246,7 +229,8 @@ cancelAllReminders(callback: AsyncCallback&lt;void&gt;): void
``` ```
reminderAgent.cancelAllReminders((err, data) =>{ reminderAgent.cancelAllReminders((err, data) =>{
console.log("do next")}) console.log("cancelAllReminders callback")
})
``` ```
...@@ -268,7 +252,8 @@ cancelAllReminders(): Promise&lt;void&gt; ...@@ -268,7 +252,8 @@ cancelAllReminders(): Promise&lt;void&gt;
``` ```
reminderAgent.cancelAllReminders().then(() => { reminderAgent.cancelAllReminders().then(() => {
console.log("do next")}) console.log("cancelAllReminders promise")
})
``` ```
...@@ -290,16 +275,13 @@ addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;) ...@@ -290,16 +275,13 @@ addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback&lt;void&gt;)
**示例** **示例**
``` ```
export default { data: { mySlot: { 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(this.mySlot, (err, data) => {
console.log("addNotificationSlot callback");
});
``` ```
...@@ -326,16 +308,13 @@ addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt; ...@@ -326,16 +308,13 @@ addNotificationSlot(slot: NotificationSlot): Promise&lt;void&gt;
**示例** **示例**
``` ```
export default { data: { mySlot: { 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(this.mySlot).then(() => {
console.log("addNotificationSlot promise");
});
``` ```
...@@ -357,12 +336,9 @@ removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback& ...@@ -357,12 +336,9 @@ removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback&
**示例** **示例**
``` ```
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");
}); });
}
}
``` ```
...@@ -389,12 +365,9 @@ removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt; ...@@ -389,12 +365,9 @@ removeNotificationSlot(slotType: notification.SlotType): Promise&lt;void&gt;
**示例** **示例**
``` ```
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.
先完成此消息的编辑!
想要评论请 注册