You can set your application to call the **ReminderRequest** class 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, even when your application is frozen or exits.
You can set your application to call the **ReminderRequest** class 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, even when your application is frozen or exits.
## Available APIs
**reminderAgent** encapsulates the methods for publishing and canceling reminders.
| function publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback\<number>): void;<br>function publishReminder(reminderReq: ReminderRequest): Promise\<number>; | Publishes a scheduled reminder.<br>The maximum number of valid notifications (excluding expired ones that will not pop up again) is 30 for one application and 2000 for the entire system. |
| function cancelReminder(reminderId: number, callback: AsyncCallback\<void>): void;<br/>function cancelReminder(reminderId: number): Promise\<void>; | Cancels a specified reminder. (The value of **reminderId** is obtained from the return value of **publishReminder**.) |
| function getValidReminders(callback: AsyncCallback<Array\<ReminderRequest>>): void;<br/>function getValidReminders(): Promise<Array\<ReminderRequest>>; | Obtains all valid reminders set by the current application. |
| function cancelAllReminders(callback: AsyncCallback\<void>): void;<br/>function cancelAllReminders(): Promise\<void>; | Cancels all reminders set by the current application. |
| function addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback\<void>): void;<br/>function addNotificationSlot(slot: NotificationSlot): Promise\<void>; | Registers a NotificationSlot instance to be used by the reminder. |
| function removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback\<void>): void;function removeNotificationSlot(slotType: notification.SlotType): Promise\<void>; | Removes a NotificationSlot instance of a specified type. |
**ActionButtonType** enumerates types of buttons displayed in a reminder notification.
| ACTION_BUTTON_TYPE_CLOSE | Close button, which can be tapped to stop the reminder alert tone, close the reminder notification, and cancel the reminder snoozing. |
**ReminderType** enumerates the reminder types.
**Table 3** ReminderType enumeration
| Name | Description |
| ---------------------- | ------------------- |
| REMINDER_TYPE_TIMER | Countdown reminder. |
| REMINDER_TYPE_CALENDAR | Calendar reminder. |
| REMINDER_TYPE_ALARM | Alarm reminder. |
**ActionButton** defines a button displayed in the reminder notification.
| pkgName | string | Yes | Name of the package redirected to when the reminder notification is clicked. |
| abilityName | string | Yes | Name of the ability redirected to when the reminder notification is clicked. |
**MaxScreenWantAgent** sets the name of the target package and ability to start automatically when the reminder arrives and the device is not in use. If the device is in use, a notification will be displayed.
| reminderType | ReminderType | Yes | Type of the reminder. |
| actionButton | [ActionButton?, ActionButton?] | No | Action button displayed in the reminder notification. |
| wantAgent | WantAgent | No | Information about the ability that is redirected to when the notification is clicked. |
| 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. |
| ringDuration | number | No | Ring duration. |
| snoozeTimes | number | No | Number of reminder snooze times. |
| timeInterval | number | No | Reminder snooze interval. |
| title | string | No | Reminder title. |
| content | string | No | Reminder content. |
| expiredContent | string | No | Extended content to be displayed when the reminder expires. |
| snoozeContent | string | No | Extended content to be displayed when the reminder is snoozing. |
| notificationId | number | No | Notification ID used by the reminder. For details, see the API reference of the **NotificationRequest.setNotificationId(int id)** method. |
| slotType | SlotType | No | Type of the slot used by the reminder. |
**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.
**Table 8** ReminderRequestCalendar instance
## Available APIs
**reminderAgent** encapsulates the APIs for publishing and canceling reminders.
| Name | Type | Mandatory | Description |
For details about the APIs, see [reminderAgent](../reference/apis/js-apis-reminderAgent.md).
| triggerTimeInSeconds | number | Yes | Number of seconds in the countdown timer. |
**LocalDateTime** defines a **LocalDateTime** instance.
**Table 11** LocalDateTime instance
**Table 1** Major APIs in reminderAgent
| Name | Type | Mandatory | Description |
| Name| Description|
| ------ | ------ | --------- | ----------- |
| -------- | -------- |
| year | number | Yes | Year. |
| publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void<br>publishReminder(reminderReq: ReminderRequest): Promise<number> | Publishes a scheduled reminder.<br>The maximum number of valid notifications (excluding expired ones that will not pop up again) is 30 for one application and 2000 for the entire system. |
| month | number | Yes | Month. |
| cancelReminder(reminderId: number, callback: AsyncCallback<void>): void<br>cancelReminder(reminderId: number): Promise<void> | Cancels a specified reminder. (The value of **reminderId** is obtained from the return value of **publishReminder**.)|
| day | number | Yes | Date. |
| getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void<br>getValidReminders(): Promise<Array<ReminderRequest>> | Obtains all valid reminders set by the current application.|
| hour | number | Yes | Hour. |
| cancelAllReminders(callback: AsyncCallback<void>): void<br>cancelAllReminders(): Promise<void> | Cancels all reminders set by the current application.|
| minute | number | Yes | Minute. |
| addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void<br>addNotificationSlot(slot: NotificationSlot): Promise<void> | Registers a **NotificationSlot** instance to be used by the reminder.|
| second | number | No | Second. |
| removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void<br>removeNotificationSlot(slotType: notification.SlotType): Promise<void> | Removes a **NotificationSlot** instance of a specified type.|
## How to Develop
## How to Develop
> **NOTE**
> **NOTE**
> To publish a reminder, your application needs to apply for the **ohos.permission.PUBLISH_AGENT_REMINDER** permission.
>
> 1. To publish a reminder through the reminder agent, your application needs to apply for the **ohos.permission.PUBLISH_AGENT_REMINDER** permission.
>
> 2. Your application must have notification enabled. For details, see [Notification.requestEnableNotification](../reference/apis/js-apis-notification.md#notificationrequestenablenotification8).
Publish a 10-second countdown reminder.
1. Define a reminder agent.
1. Define a countdown timer instance.
Sample code for defining a reminder agent for a countdown timer:
Publishes an agent-powered reminder. This API uses an asynchronous callback to return the result.
Publishes 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](../reference/apis/js-apis-notification.md#notificationrequestenablenotification8).
Publishes an agent-powered reminder. This API uses a promise callback to return the result.
Publishes 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](../reference/apis/js-apis-notification.md#notificationrequestenablenotification8).
@@ -455,7 +456,7 @@ Sets the package and ability that are redirected to when the reminder notificati
...
@@ -455,7 +456,7 @@ Sets the package and ability that are redirected to when the reminder notificati
## MaxScreenWantAgent
## MaxScreenWantAgent
Sets the name of the target package and ability to start automatically when the reminder arrives and the device is not in use. If the device is in use, a notification will be displayed.
Provides the information about the target package and ability to start automatically when the reminder is displayed in full-screen mode. This API is reserved.
@@ -474,7 +475,7 @@ Defines the reminder to publish.
...
@@ -474,7 +475,7 @@ Defines the reminder to publish.
| Name| Type| Mandatory| Description|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| -------- | -------- | -------- | -------- |
| reminderType | ReminderType | Yes| Type of the reminder.|
| reminderType | ReminderType | Yes| Type of the reminder.|
| actionButton | [ActionButton?, ActionButton?] | No| Action button displayed in the reminder notification. (The parameter is optional. Up to two buttons are supported.)|
| actionButton | [ActionButton?, ActionButton?] | No| Button displayed in the reminder notification. (The parameter is optional. Up to two buttons are supported.)|
| wantAgent | WantAgent | No| Information about the ability that is redirected to when the notification is clicked.|
| wantAgent | WantAgent | No| Information about the ability that is redirected to when the notification is clicked.|
| 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.|
| 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.|
| id | string | Yes | Unique ID of the component. The value can contain a maximum of 128 characters.|
| id | string | Yes | Unique ID of the component. The value can contain a maximum of 128 characters.|
| type | string | Yes | Type of the component. The options are as follows:<br>-**surface**: The content of this component is displayed individually, without being combined with that of other components.<br>- **component**: The content of this component is displayed after having been combined with that of other components.|
| type | string | Yes | Type of the component. The options are as follows:<br>-**surface**: The content of this component is displayed individually, without being combined with that of other components.<br>-**component**: The content of this component is displayed after having been combined with that of other components.|
| libraryname | string | No | Name of the dynamic library generated after compilation at the application native layer.|
| libraryname | string | No | Name of the dynamic library generated after compilation at the application native layer.|
| controller | [XComponentcontroller](#xcomponentcontroller) | No | Controller bound to the component, which can be used to invoke methods of the component.|
| controller | [XComponentcontroller](#xcomponentcontroller) | No | Controller bound to the component, which can be used to invoke methods of the component.|
...
@@ -59,7 +59,7 @@ xcomponentController: XComponentController = new XComponentController()
...
@@ -59,7 +59,7 @@ xcomponentController: XComponentController = new XComponentController()
### getXComponentSurfaceId
### getXComponentSurfaceId
getXComponentSurfaceId(): string
getXComponentSurfaceId()
Obtains the ID of the surface held by the **\<XComponent>**. The ID can be used for @ohos interfaces, such as camera-related interfaces.
Obtains the ID of the surface held by the **\<XComponent>**. The ID can be used for @ohos interfaces, such as camera-related interfaces.
...
@@ -71,9 +71,10 @@ Obtains the ID of the surface held by the **\<XComponent>**. The ID can be used
...
@@ -71,9 +71,10 @@ Obtains the ID of the surface held by the **\<XComponent>**. The ID can be used
| ------ | ----------------------- |
| ------ | ----------------------- |
| string | ID of the surface held by the **\<XComponent>**.|
| string | ID of the surface held by the **\<XComponent>**.|
| size | number | No | Font size. If the value is of the number type, the unit fp is used. |
| weight | number | No | Font weight. For the number type, the value ranges from 100 to 900, at an interval of 100. The default value is **400**. A larger value indicates a larger font weight.|
| family | [FontWeight](../reference/arkui-ts/ts-appendix-enums.md#fontweight)\| number \| string | No | Font family of the text. Use commas (,) to separate multiple fonts. The priority of the fonts is the sequence in which they are placed. An example value is **'Arial, sans-serif'**.|
| style | string \| Resource | No | Font style. |
## Area<sup>8+</sup>
The **Area** type is used to describe the area information of the target element.
| CustomBuilder | () => any | Builder of component attribute methods for defining custom UI descriptions. This type of method must be decorated by **@Builder**. For details, see [@Builder](../../ui/ts-component-based-builder.md).|
The @State decorated variable is the internal state data of the component. When the state data is modified, the build method of the component is called to refresh the UI.
The @State decorated variable is the internal state data of the component. When the state data is modified, the build method of the component is called to refresh the UI. Note that the @State decorator cannot listen for data changes at the inner layer.
The @State data has the following features:
The @State data has the following features:
...
@@ -20,8 +20,8 @@ The @State data has the following features:
...
@@ -20,8 +20,8 @@ The @State data has the following features:
## Simple Example of @State Decorated Attribute
## Simple Example of @State Decorated Attribute
```ts
```
// xxx.ets
@Entry
@Entry
@Component
@Component
structMyComponent{
structMyComponent{
...
@@ -45,9 +45,9 @@ struct MyComponent {
...
@@ -45,9 +45,9 @@ struct MyComponent {
## Complex Example of @State Decorated Variable
## Complex Example of @State Decorated Variable
```ts
```
// Customize the status data class.
// Customize the status data class.
// xxx.ets
classModel{
classModel{
value:string
value:string
constructor(value:string){
constructor(value:string){
...
@@ -60,8 +60,8 @@ class Model {
...
@@ -60,8 +60,8 @@ class Model {
structEntryComponent{
structEntryComponent{
build(){
build(){
Column(){
Column(){
MyComponent({count: 1, increaseBy: 2}) // MyComponent1 in this document
MyComponent({count:1,increaseBy:2})// MyComponent1 in this document
MyComponent({title: {value: 'Hello, World 2'}, count: 7}) //MyComponent2 in this document
MyComponent({title:{value:'Hello, World 2'},count:7})//MyComponent2 in this document
}
}
}
}
}
}
...
@@ -102,6 +102,6 @@ In the preceding example:
...
@@ -102,6 +102,6 @@ In the preceding example:
- When creating a MyComponent instance, initialize the variables in the component based on the variable name. For example:
- When creating a MyComponent instance, initialize the variables in the component based on the variable name. For example:
```
```ts
MyComponent({title:{value:'Hello, World 2'},count:7})
MyComponent({title:{value:'Hello, World 2'},count:7})