has.addPhoneCalendar(Object object)
Adds events to the system calendar.
Since: 1.0.4
Required permissions:
ohos.permission.READ_CALENDAR and ohos.permission.WRITE_CALENDAR, which need to be declared in module.json5.
scope.addPhoneCalendar permission, which is applied for in has.authorize.
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| title | string | - | Yes | Event title. |
| startTime | number | - | Yes | Unix timestamp of the start time. |
| allDay | boolean | false | No | Whether the event is an all-day event. The default value is false. |
| description | string | - | No | Event description. |
| location | string | - | No | Event location. |
| endTime | string | - | No | Unix timestamp of the end time. By default, the end time is the same as the start time. |
| alarm | boolean | true | No | Whether to send a reminder. The default value is true. |
| alarmOffset | number | 0 | No | Time in advance for sending a reminder, in seconds. The value is automatically rounded up. If the value is less than 60 seconds, it is considered as 0 minutes. The default value is 0, indicating that a reminder is sent at the start time. |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 12000701 | addPhoneCalendar error. For details, see Calendar Error Codes. |
Example:
has.authorize({
scope: 'scope.addPhoneCalendar',
success: () => {
has.addPhoneCalendar({
title: 'One-off event',
startTime: 1730379600,
description: 'Event description',
location: 'Event location',
endTime: '1730386800',
alarm: true,
alarmOffset: 60,
});
}
}); has.addPhoneRepeatCalendar(Object object)
Adds a recurring event to the system calendar.
Since: 1.0.4
Required permissions:
ohos.permission.READ_CALENDAR and ohos.permission.WRITE_CALENDAR, which need to be declared in module.json5.
The scope.addPhoneCalendar permission, which is applied for in has.authorize.
Parameters
The input parameter is an object containing the following fields.
| Parameter | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| title | string | - | Yes | Event title. |
| startTime | number | - | Yes | Unix timestamp of the start time. |
| allDay | boolean | false | No | Whether the event is an all-day event. The default value is false. |
| description | string | - | No | Event description. |
| location | string | - | No | Event location. |
| endTime | string | - | No | Unix timestamp of the end time. By default, the end time is the same as the start time. |
| alarm | boolean | true | No | Whether to send a reminder. The default value is true. |
| alarmOffset | number | 0 | No | Time in advance for sending a reminder, in seconds. The value is automatically rounded up. If the value is less than 60 seconds, it is considered as 0 minutes. The default value is 0, indicating that a reminder is sent at the start time. |
| repeatInterval | string | month | No | Repetition period. The default value is month. - day: repeated by day. - week: repeated by week. - month: repeated by month. The date cannot be greater than the 28th. - year: repeated by year. |
| repeatEndTime | number | - | No | Unix timestamp for the end time of the repetition period. If this parameter is left empty, repetition always remains valid. |
| success | function | - | No | Callback triggered when the API call is successful. |
| fail | function | - | No | Callback triggered when the API call fails. |
| complete | function | - | No | Callback triggered when the API call is complete, regardless of success or failure. |
Error code information
| Error Code | Error Message |
|---|---|
| 102 | time is invalid. |
| 12000801 | addPhoneRepeatCalendar error. |
Example:
has.authorize({
scope: 'scope.addPhoneCalendar',
success: () => {
has.addPhoneRepeatCalendar({
title: 'Repeated event',
startTime: 1730379600,
description: 'Event description',
location: 'Event location',
endTime: '1730386800',
alarm: true,
alarmOffset: 60,
repeatInterval: 'day',
repeatEndTime: 1732978800
});
}
});