1# @ohos.reminderAgentManager (reminderAgentManager) 2 3The **reminderAgentManager** module provides APIs for publishing scheduled reminders through the reminder agent. 4 5You can use the APIs to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background when your application is frozen or exits. 6 7> **NOTE** 8> 9> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 10 11 12## Modules to Import 13 14``` 15import reminderAgentManager from'@ohos.reminderAgentManager'; 16``` 17 18 19## reminderAgentManager.publishReminder 20 21publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void 22 23Publishes a reminder through the reminder agent. This API uses an asynchronous callback to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8). 24 25**Required permissions**: ohos.permission.PUBLISH_AGENT_REMINDER 26 27**System capability**: SystemCapability.Notification.ReminderAgent 28 29**Parameters** 30 31 | Name| Type| Mandatory| Description| 32 | -------- | -------- | -------- | -------- | 33 | reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.| 34 | callback | AsyncCallback<number> | Yes| Callback used to return the published reminder's ID.| 35 36**Error codes** 37 38For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 39 40| ID | Error Message| 41| --------- | ------- | 42| 1700001 | Notification is not enabled. | 43| 1700002 | The number of reminders exceeds the limit. | 44 45**Example** 46```js 47let timer = { 48 reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER, 49 triggerTimeInSeconds: 10 50} 51try { 52 reminderAgentManager.publishReminder(timer, (err, reminderId) => { 53 if (err) { 54 console.log("callback err code:" + err.code + " message:" + err.message); 55 } else { 56 console.log("callback, reminderId = " + reminderId); 57 } 58 }); 59} catch (error) { 60 console.log("publishReminder code:" + error.code + " message:" + error.message); 61}; 62``` 63 64 65## reminderAgentManager.publishReminder 66 67publishReminder(reminderReq: ReminderRequest): Promise<number> 68 69Publishes a reminder through the reminder agent. This API uses a promise to return the result. It can be called only when notification is enabled for the application through [Notification.requestEnableNotification](js-apis-notification.md#notificationrequestenablenotification8). 70 71**Required permissions**: ohos.permission.PUBLISH_AGENT_REMINDER 72 73**System capability**: SystemCapability.Notification.ReminderAgent 74 75**Parameters** 76 | Name| Type| Mandatory| Description| 77 | -------- | -------- | -------- | -------- | 78 | reminderReq | [ReminderRequest](#reminderrequest) | Yes| Reminder to be published.| 79 80**Return value** 81 | Type| Description| 82 | -------- | -------- | 83 | Promise<number> | Promise used to return the published reminder's ID.| 84 85**Error codes** 86 87For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 88 89| ID | Error Message| 90| --------- | ------- | 91| 1700001 | Notification is not enabled. | 92| 1700002 | The number of reminders exceeds the limit. | 93 94**Example** 95```js 96let timer = { 97 reminderType: reminderAgentManager.ReminderType.REMINDER_TYPE_TIMER, 98 triggerTimeInSeconds: 10 99} 100try { 101 reminderAgentManager.publishReminder(timer).then((reminderId) => { 102 console.log("promise, reminderId = " + reminderId); 103 }).catch(err => { 104 console.log("promise err code:" + err.code + " message:" + err.message); 105 }); 106} catch (error) { 107 console.log("publishReminder code:" + error.code + " message:" + error.message); 108}; 109``` 110 111 112## reminderAgentManager.cancelReminder 113 114cancelReminder(reminderId: number, callback: AsyncCallback<void>): void 115 116Cancels the reminder with the specified ID. This API uses an asynchronous callback to return the cancellation result. 117 118**System capability**: SystemCapability.Notification.ReminderAgent 119 120**Parameters** 121 122| Name| Type| Mandatory| Description| 123| -------- | -------- | -------- | -------- | 124| reminderId | number | Yes| ID of the reminder to cancel.| 125| callback | AsyncCallback<void> | Yes| Asynchronous callback used to return the result.| 126 127**Error codes** 128 129For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 130 131| ID | Error Message| 132| --------- | ------- | 133| 1700003 | The reminder does not exist. | 134| 1700004 | The bundle name does not exist. | 135 136**Example** 137 138```js 139try { 140 reminderAgentManager.cancelReminder(1, (err, data) => { 141 if (err) { 142 console.log("callback err code:" + err.code + " message:" + err.message); 143 } else { 144 console.log("cancelReminder callback"); 145 } 146 }); 147} catch (error) { 148 console.log("cancelReminder code:" + error.code + " message:" + error.message); 149}; 150``` 151 152 153## reminderAgentManager.cancelReminder 154 155cancelReminder(reminderId: number): Promise<void> 156 157Cancels the reminder with the specified ID. This API uses a promise to return the cancellation result. 158 159**System capability**: SystemCapability.Notification.ReminderAgent 160 161**Parameters** 162 163| Name| Type| Mandatory| Description| 164| -------- | -------- | -------- | -------- | 165| reminderId | number | Yes| ID of the reminder to cancel.| 166 167**Return value** 168 169| Type| Description| 170| -------- | -------- | 171| Promise<void> | Promise used to return the result.| 172 173**Error codes** 174 175For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 176 177| ID | Error Message| 178| --------- | ------- | 179| 1700003 | The reminder does not exist. | 180| 1700004 | The bundle name does not exist. | 181 182**Example** 183 184```js 185try { 186 reminderAgentManager.cancelReminder(1).then(() => { 187 console.log("cancelReminder promise"); 188 }).catch(err => { 189 console.log("promise err code:" + err.code + " message:" + err.message); 190 }); 191} catch (error) { 192 console.log("cancelReminder code:" + error.code + " message:" + error.message); 193}; 194``` 195 196 197## reminderAgentManager.getValidReminders 198 199getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void 200 201Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the reminders. 202 203**System capability**: SystemCapability.Notification.ReminderAgent 204 205**Parameters** 206 207| Name| Type| Mandatory| Description| 208| -------- | -------- | -------- | -------- | 209| callback | AsyncCallback<Array<[ReminderRequest](#reminderrequest)>> | Yes| Asynchronous callback used to return an array of all valid reminders set by the current application.| 210 211**Error codes** 212 213For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 214 215| ID | Error Message| 216| --------- | ------- | 217| 1700004 | The bundle name does not exist. | 218 219**Example** 220 221```js 222try { 223 reminderAgentManager.getValidReminders((err, reminders) => { 224 if (err) { 225 console.log("callback err code:" + err.code + " message:" + err.message); 226 } else { 227 console.log("callback, getValidReminders length = " + reminders.length); 228 for (let i = 0; i < reminders.length; i++) { 229 console.log("getValidReminders = " + reminders[i]); 230 console.log("getValidReminders, reminderType = " + reminders[i].reminderType); 231 for (let j = 0; j < reminders[i].actionButton.length; j++) { 232 console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title); 233 console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type); 234 } 235 console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName); 236 console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName); 237 console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName); 238 console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName); 239 console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration); 240 console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes); 241 console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval); 242 console.log("getValidReminders, title = " + reminders[i].title); 243 console.log("getValidReminders, content = " + reminders[i].content); 244 console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent); 245 console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent); 246 console.log("getValidReminders, notificationId = " + reminders[i].notificationId); 247 console.log("getValidReminders, slotType = " + reminders[i].slotType); 248 } 249 } 250 }) 251} catch (error) { 252 console.log("getValidReminders code:" + error.code + " message:" + error.message); 253}; 254``` 255 256 257## reminderAgentManager.getValidReminders 258 259getValidReminders(): Promise<Array<ReminderRequest>> 260 261Obtains all valid (not yet expired) reminders set by the current application. This API uses a promise to return the reminders. 262 263**System capability**: SystemCapability.Notification.ReminderAgent 264 265**Return value** 266 267| Type| Description| 268| -------- | -------- | 269| Promise<Array<[ReminderRequest](#reminderrequest)>> | Promise used to return an array of all valid reminders set by the current application.| 270 271**Error codes** 272 273For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 274 275| ID | Error Message| 276| --------- | ------- | 277| 1700004 | The bundle name does not exist. | 278 279**Example** 280 281```js 282try { 283 reminderAgentManager.getValidReminders().then((reminders) => { 284 console.log("promise, getValidReminders length = " + reminders.length); 285 for (let i = 0; i < reminders.length; i++) { 286 console.log("getValidReminders = " + reminders[i]); 287 console.log("getValidReminders, reminderType = " + reminders[i].reminderType); 288 for (let j = 0; j < reminders[i].actionButton.length; j++) { 289 console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title); 290 console.log("getValidReminders, actionButton.type = " + reminders[i].actionButton[j].type); 291 } 292 console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent.pkgName); 293 console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent.abilityName); 294 console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent.pkgName); 295 console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent.abilityName); 296 console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration); 297 console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes); 298 console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval); 299 console.log("getValidReminders, title = " + reminders[i].title); 300 console.log("getValidReminders, content = " + reminders[i].content); 301 console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent); 302 console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent); 303 console.log("getValidReminders, notificationId = " + reminders[i].notificationId); 304 console.log("getValidReminders, slotType = " + reminders[i].slotType); 305 } 306 }).catch(err => { 307 console.log("promise err code:" + err.code + " message:" + err.message); 308 }); 309} catch (error) { 310 console.log("getValidReminders code:" + error.code + " message:" + error.message); 311}; 312``` 313 314 315## reminderAgentManager.cancelAllReminders 316 317cancelAllReminders(callback: AsyncCallback<void>): void 318 319Cancels all reminders set by the current application. This API uses an asynchronous callback to return the cancellation result. 320 321**System capability**: SystemCapability.Notification.ReminderAgent 322 323**Parameters** 324 325| Name| Type| Mandatory| Description| 326| -------- | -------- | -------- | -------- | 327| callback | AsyncCallback<void> | Yes| Asynchronous callback used to return the result.| 328 329**Error codes** 330 331For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 332 333| ID | Error Message| 334| --------- | ------- | 335| 1700004 | The bundle name does not exist. | 336 337**Example** 338 339```js 340try { 341 reminderAgentManager.cancelAllReminders((err, data) =>{ 342 if (err) { 343 console.log("callback err code:" + err.code + " message:" + err.message); 344 } else { 345 console.log("cancelAllReminders callback") 346 } 347 }) 348} catch (error) { 349 console.log("cancelAllReminders code:" + error.code + " message:" + error.message); 350}; 351``` 352 353 354## reminderAgentManager.cancelAllReminders 355 356cancelAllReminders(): Promise<void> 357 358Cancels all reminders set by the current application. This API uses a promise to return the cancellation result. 359 360**System capability**: SystemCapability.Notification.ReminderAgent 361 362**Return value** 363 364| Type| Description| 365| -------- | -------- | 366| Promise<void> | Promise used to return the result.| 367 368**Error codes** 369 370For details about the error codes, see [reminderAgentManager Error Codes](../errorcodes/errorcode-reminderAgentManager.md). 371 372| ID | Error Message| 373| --------- | ------- | 374| 1700004 | The bundle name does not exist. | 375 376**Example** 377 378```js 379try { 380 reminderAgentManager.cancelAllReminders().then(() => { 381 console.log("cancelAllReminders promise") 382 }).catch(err => { 383 console.log("promise err code:" + err.code + " message:" + err.message); 384 }); 385} catch (error) { 386 console.log("cancelAllReminders code:" + error.code + " message:" + error.message); 387}; 388``` 389 390 391## reminderAgentManager.addNotificationSlot 392 393addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void 394 395Adds a notification slot. This API uses an asynchronous callback to return the result. 396 397**System capability**: SystemCapability.Notification.ReminderAgent 398 399**Parameters** 400 401| Name| Type| Mandatory| Description| 402| -------- | -------- | -------- | -------- | 403| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.| 404| callback | AsyncCallback<void> | Yes| Asynchronous callback used to return the result.| 405 406**Example** 407 408```js 409import notification from '@ohos.notification' 410 411let mySlot = { 412 type: notification.SlotType.SOCIAL_COMMUNICATION 413} 414try { 415 reminderAgentManager.addNotificationSlot(mySlot, (err, data) => { 416 if (err) { 417 console.log("callback err code:" + err.code + " message:" + err.message); 418 } else { 419 console.log("addNotificationSlot callback"); 420 } 421 }); 422} catch (error) { 423 console.log("addNotificationSlot code:" + error.code + " message:" + error.message); 424}; 425``` 426 427 428## reminderAgentManager.addNotificationSlot 429 430addNotificationSlot(slot: NotificationSlot): Promise<void> 431 432Adds a notification slot. This API uses a promise to return the result. 433 434**System capability**: SystemCapability.Notification.ReminderAgent 435 436**Parameters** 437 438| Name| Type| Mandatory| Description| 439| -------- | -------- | -------- | -------- | 440| slot | [NotificationSlot](js-apis-notification.md#notificationslot) | Yes| Notification slot, whose type can be set.| 441 442**Return value** 443 444| Type| Description| 445| -------- | -------- | 446| Promise<void> | Promise used to return the result.| 447 448**Example** 449 450```js 451import notification from '@ohos.notification' 452 453let mySlot = { 454 type: notification.SlotType.SOCIAL_COMMUNICATION 455} 456try { 457 reminderAgentManager.addNotificationSlot(mySlot).then(() => { 458 console.log("addNotificationSlot promise"); 459 }).catch(err => { 460 console.log("promise err code:" + err.code + " message:" + err.message); 461 }); 462} catch (error) { 463 console.log("addNotificationSlot code:" + error.code + " message:" + error.message); 464}; 465``` 466 467 468## reminderAgentManager.removeNotificationSlot 469 470removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void 471 472Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result. 473 474**System capability**: SystemCapability.Notification.ReminderAgent 475 476**Parameters** 477 478| Name| Type| Mandatory| Description| 479| -------- | -------- | -------- | -------- | 480| slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.| 481| callback | AsyncCallback<void> | Yes| Asynchronous callback used to return the result.| 482 483**Example** 484 485```js 486import notification from '@ohos.notification' 487 488try { 489 reminderAgentManager.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) => { 490 if (err) { 491 console.log("callback err code:" + err.code + " message:" + err.message); 492 } else { 493 console.log("removeNotificationSlot callback"); 494 } 495 }); 496} catch (error) { 497 console.log("removeNotificationSlot code:" + error.code + " message:" + error.message); 498}; 499``` 500 501 502## reminderAgentManager.removeNotificationSlot 503 504removeNotificationSlot(slotType: notification.SlotType): Promise<void> 505 506Removes a notification slot of a specified type. This API uses a promise to return the result. 507 508**System capability**: SystemCapability.Notification.ReminderAgent 509 510**Parameters** 511 512| Name| Type| Mandatory| Description| 513| -------- | -------- | -------- | -------- | 514| slotType | [notification.SlotType](js-apis-notification.md#slottype) | Yes| Type of the notification slot to remove.| 515 516**Return value** 517 518| Type| Description| 519| -------- | -------- | 520| Promise<void> | Promise used to return the result.| 521 522**Example** 523 524```js 525import notification from '@ohos.notification' 526 527try { 528 reminderAgentManager.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => { 529 console.log("removeNotificationSlot promise"); 530 }).catch(err => { 531 console.log("promise err code:" + err.code + " message:" + err.message); 532 }); 533} catch (error) { 534 console.log("removeNotificationSlot code:" + error.code + " message:" + error.message); 535}; 536``` 537 538## ActionButtonType 539 540Enumerates button types. 541 542**System capability**: SystemCapability.Notification.ReminderAgent 543 544| Name| Value| Description| 545| -------- | -------- | -------- | 546| ACTION_BUTTON_TYPE_CLOSE | 0 | Button for closing the reminder.| 547| ACTION_BUTTON_TYPE_SNOOZE | 1 | Button for snoozing the reminder.| 548 549 550## ReminderType 551 552Enumerates reminder types. 553 554**System capability**: SystemCapability.Notification.ReminderAgent 555 556| Name| Value| Description| 557| -------- | -------- | -------- | 558| REMINDER_TYPE_TIMER | 0 | Countdown reminder.| 559| REMINDER_TYPE_CALENDAR | 1 | Calendar reminder.| 560| REMINDER_TYPE_ALARM | 2 | Alarm reminder.| 561 562 563## ActionButton 564 565Defines a button displayed in the reminder notification. 566 567**System capability**: SystemCapability.Notification.ReminderAgent 568 569| Name| Type| Mandatory| Description| 570| -------- | -------- | -------- | -------- | 571| title | string | Yes| Text on the button.| 572| type | [ActionButtonType](#actionbuttontype) | Yes| Button type.| 573 574 575## WantAgent 576 577Sets the package and ability that are redirected to when the reminder notification is clicked. 578 579**System capability**: SystemCapability.Notification.ReminderAgent 580 581| Name| Type| Mandatory| Description| 582| -------- | -------- | -------- | -------- | 583| pkgName | string | Yes| Name of the HAP that is redirected to when the reminder notification is clicked.| 584| abilityName | string | Yes| Name of the ability that is redirected to when the reminder notification is clicked.| 585 586 587## MaxScreenWantAgent 588 589Provides the information about the target package and ability to start automatically when the reminder is displayed in full-screen mode. This API is reserved. 590 591**System capability**: SystemCapability.Notification.ReminderAgent 592 593| Name| Type| Mandatory| Description| 594| -------- | -------- | -------- | -------- | 595| pkgName | string | Yes| Name of the HAP that is automatically started when the reminder arrives and the device is not in use.| 596| abilityName | string | Yes| Name of the ability that is automatically started when the reminder arrives and the device is not in use.| 597 598 599## ReminderRequest 600 601Defines the reminder to publish. 602 603**System capability**: SystemCapability.Notification.ReminderAgent 604 605| Name| Type| Mandatory| Description| 606| -------- | -------- | -------- | -------- | 607| reminderType | [ReminderType](#remindertype) | Yes| Type of the reminder.| 608| actionButton | [ActionButton](#actionbutton) | No| Button displayed in the reminder notification. (The parameter is optional. Up to two buttons are supported.)| 609| wantAgent | [WantAgent](#wantagent) | No| Information about the ability that is redirected to when the notification is clicked.| 610| maxScreenWantAgent | [MaxScreenWantAgent](#maxscreenwantagent) | No| Information about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.| 611| ringDuration | number | No| Ringing duration, in seconds. The default value is **1**.| 612| snoozeTimes | number | No| Number of reminder snooze times. The default value is **0**.| 613| timeInterval | number | No| Reminder snooze interval, in seconds. The default value is **0**.| 614| title | string | No| Reminder title.| 615| content | string | No| Reminder content.| 616| expiredContent | string | No| Content to be displayed after the reminder expires.| 617| snoozeContent | string | No| Content to be displayed when the reminder is snoozing.| 618| notificationId | number | No| Notification ID used by the reminder. If there are reminders with the same notification ID, the later one will overwrite the earlier one.| 619| slotType | [notification.SlotType](js-apis-notification.md#slottype) | No| Type of the slot used by the reminder.| 620 621 622## ReminderRequestCalendar 623 624ReminderRequestCalendar extends ReminderRequest 625 626Defines a reminder for a calendar event. 627 628**System capability**: SystemCapability.Notification.ReminderAgent 629 630| Name| Type| Mandatory| Description| 631| -------- | -------- | -------- | -------- | 632| dateTime | [LocalDateTime](#localdatetime) | Yes| Reminder time.| 633| repeatMonths | Array<number> | No| Month in which the reminder repeats.| 634| repeatDays | Array<number> | No| Date on which the reminder repeats.| 635 636 637## ReminderRequestAlarm 638 639ReminderRequestAlarm extends ReminderRequest 640 641Defines a reminder for an alarm. 642 643**System capability**: SystemCapability.Notification.ReminderAgent 644 645| Name| Type| Mandatory| Description| 646| -------- | -------- | -------- | -------- | 647| hour | number | Yes| Hour portion of the reminder time.| 648| minute | number | Yes| Minute portion of the reminder time.| 649| daysOfWeek | Array<number> | No| Days of a week when the reminder repeats. The value ranges from 1 to 7, corresponding to the data from Monday to Sunday.| 650 651 652## ReminderRequestTimer 653 654ReminderRequestTimer extends ReminderRequest 655 656Defines a reminder for a scheduled timer. 657 658**System capability**: SystemCapability.Notification.ReminderAgent 659 660| Name| Type| Mandatory| Description| 661| -------- | -------- | -------- | -------- | 662| triggerTimeInSeconds | number | Yes| Number of seconds in the countdown timer.| 663 664 665## LocalDateTime 666 667Sets the time information for a calendar reminder. 668 669**System capability**: SystemCapability.Notification.ReminderAgent 670 671| Name| Type| Mandatory| Description| 672| -------- | -------- | -------- | -------- | 673| year | number | Yes| Year.| 674| month | number | Yes| Month. The value ranges from 1 to 12.| 675| day | number | Yes| Day. The value ranges from 1 to 31.| 676| hour | number | Yes| Hour. The value ranges from 0 to 23.| 677| minute | number | Yes| Minute. The value ranges from 0 to 59.| 678| second | number | No| Second. The value ranges from 0 to 59.| 679