harmony 鸿蒙@ohos.reminderAgent (reminderAgent)

2022-08-09 浏览 (801)

@ohos.reminderAgent (reminderAgent)

The reminderAgent module provides APIs for publishing scheduled reminders through the reminder agent.

You 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.

NOTE

This module is deprecated since API version 9. You are advised to use @ohos.reminderAgentManager instead.

The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Modules to Import

import reminderAgent from'@ohos.reminderAgent';

reminderAgent.publishReminder(deprecated)

publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback<number>): void

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.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.publishReminder.

Required permissions: ohos.permission.PUBLISH_AGENT_REMINDER

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
reminderReqReminderRequestYesReminder to be published.
callbackAsyncCallback<number>YesCallback used to return the published reminder's ID.

Example

import { BusinessError } from '@ohos.base';

let timer:reminderAgent.ReminderRequestTimer = {
  reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
  triggerTimeInSeconds: 10
}

reminderAgent.publishReminder(timer, (err: BusinessError, reminderId: number) => {
  console.log("callback, reminderId = " + reminderId);
});

reminderAgent.publishReminder(deprecated)

publishReminder(reminderReq: ReminderRequest): Promise<number>

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.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.publishReminder.

Required permissions: ohos.permission.PUBLISH_AGENT_REMINDER

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
reminderReqReminderRequestYesReminder to be published.

Return value

TypeDescription
Promise<number>Promise used to return the published reminder's ID.

Example

let timer:reminderAgent.ReminderRequestTimer = {
  reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
  triggerTimeInSeconds: 10
}

reminderAgent.publishReminder(timer).then((reminderId: number) => {
  console.log("promise, reminderId = " + reminderId);
});

reminderAgent.cancelReminder(deprecated)

cancelReminder(reminderId: number, callback: AsyncCallback<void>): void

Cancels the reminder with the specified ID. This API uses an asynchronous callback to return the cancellation result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.cancelReminder.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
reminderIdnumberYesID of the reminder to cancel. The value is obtained by calling publishReminder.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import { BusinessError } from '@ohos.base';

reminderAgent.cancelReminder(1, (err: BusinessError, data: void) => {
  console.log("cancelReminder callback");
});

reminderAgent.cancelReminder(deprecated)

cancelReminder(reminderId: number): Promise<void>

Cancels the reminder with the specified ID. This API uses a promise to return the cancellation result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.cancelReminder.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
reminderIdnumberYesID of the reminder to cancel. The value is obtained by calling publishReminder.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Example

reminderAgent.cancelReminder(1).then(() => {
    console.log("cancelReminder promise");
});

reminderAgent.getValidReminders(deprecated)

getValidReminders(callback: AsyncCallback<Array<ReminderRequest>>): void

Obtains all valid (not yet expired) reminders set by the current application. This API uses an asynchronous callback to return the reminders.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.getValidReminders.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<ReminderRequest>>YesCallback used to return an array of all valid reminders set by the current application.

Example

import { BusinessError } from '@ohos.base';

reminderAgent.getValidReminders((err: BusinessError, reminders: Array<reminderAgent.ReminderRequest>) => {
  console.log("callback, getValidReminders length = " + reminders.length);
  for (let i = 0; i < reminders.length; i++) {
    console.log("getValidReminders = " + reminders[i]);
    console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
    const actionButton = reminders[i].actionButton||[];
    for (let j = 0; j < actionButton.length; j++) {
      console.log("getValidReminders, actionButton.title = " + actionButton[j]?.title);
      console.log("getValidReminders, actionButton.type = " + actionButton[j]?.type);
    }
    console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent?.pkgName);
    console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent?.abilityName);
    console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent?.pkgName);
    console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent?.abilityName);
    console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration);
    console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes);
    console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval);
    console.log("getValidReminders, title = " + reminders[i].title);
    console.log("getValidReminders, content = " + reminders[i].content);
    console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent);
    console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent);
    console.log("getValidReminders, notificationId = " + reminders[i].notificationId);
    console.log("getValidReminders, slotType = " + reminders[i].slotType);
  }
})

reminderAgent.getValidReminders(deprecated)

getValidReminders(): Promise<Array<ReminderRequest>>

Obtains all valid (not yet expired) reminders set by the current application. This API uses a promise to return the reminders.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.getValidReminders.

System capability: SystemCapability.Notification.ReminderAgent

Return value

TypeDescription
Promise<Array<ReminderRequest>>Promise used to return an array of all valid reminders set by the current application.

Example

reminderAgent.getValidReminders().then((reminders: Array<reminderAgent.ReminderRequest>) => {
  console.log("promise, getValidReminders length = " + reminders.length);
  for (let i = 0; i < reminders.length; i++) {
    console.log("getValidReminders = " + reminders[i]);
    console.log("getValidReminders, reminderType = " + reminders[i].reminderType);
    const actionButton = reminders[i].actionButton||[];
    for (let j = 0; j < actionButton.length; j++) {
      console.log("getValidReminders, actionButton.title = " + actionButton[j]?.title);
      console.log("getValidReminders, actionButton.type = " + actionButton[j]?.type);
    }
    console.log("getValidReminders, wantAgent.pkgName = " + reminders[i].wantAgent?.pkgName);
    console.log("getValidReminders, wantAgent.abilityName = " + reminders[i].wantAgent?.abilityName);
    console.log("getValidReminders, maxScreenWantAgent.pkgName = " + reminders[i].maxScreenWantAgent?.pkgName);
    console.log("getValidReminders, maxScreenWantAgent.abilityName = " + reminders[i].maxScreenWantAgent?.abilityName);
    console.log("getValidReminders, ringDuration = " + reminders[i].ringDuration);
    console.log("getValidReminders, snoozeTimes = " + reminders[i].snoozeTimes);
    console.log("getValidReminders, timeInterval = " + reminders[i].timeInterval);
    console.log("getValidReminders, title = " + reminders[i].title);
    console.log("getValidReminders, content = " + reminders[i].content);
    console.log("getValidReminders, expiredContent = " + reminders[i].expiredContent);
    console.log("getValidReminders, snoozeContent = " + reminders[i].snoozeContent);
    console.log("getValidReminders, notificationId = " + reminders[i].notificationId);
    console.log("getValidReminders, slotType = " + reminders[i].slotType);
  }
})

reminderAgent.cancelAllReminders(deprecated)

cancelAllReminders(callback: AsyncCallback<void>): void

Cancels all reminders set by the current application. This API uses an asynchronous callback to return the cancellation result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.cancelAllReminders.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import { BusinessError } from '@ohos.base';

reminderAgent.cancelAllReminders((err: BusinessError, data: void) =>{
  console.log("cancelAllReminders callback")
})

reminderAgent.cancelAllReminders(deprecated)

cancelAllReminders(): Promise<void>

Cancels all reminders set by the current application. This API uses a promise to return the cancellation result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.cancelAllReminders.

System capability: SystemCapability.Notification.ReminderAgent

Return value

TypeDescription
Promise<void>Promise used to return the result.

Example

reminderAgent.cancelAllReminders().then(() => {
    console.log("cancelAllReminders promise")
})

reminderAgent.addNotificationSlot(deprecated)

addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback<void>): void

Adds a notification slot. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.addNotificationSlot.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
slotNotificationSlotYesNotification slot, whose type can be set.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import notification from '@ohos.notificationManager'
import { BusinessError } from '@ohos.base';

let mySlot:notification.NotificationSlot = {
  type: notification.SlotType.SOCIAL_COMMUNICATION
}
reminderAgent.addNotificationSlot(mySlot, (err: BusinessError, data: void) => {
  console.log("addNotificationSlot callback");
});

reminderAgent.addNotificationSlot(deprecated)

addNotificationSlot(slot: NotificationSlot): Promise<void>

Adds a notification slot. This API uses a promise to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.addNotificationSlot.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
slotNotificationSlotYesNotification slot, whose type can be set.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Example

import notification from '@ohos.notificationManager'

let mySlot:notification.NotificationSlot = {
  type: notification.SlotType.SOCIAL_COMMUNICATION
}
reminderAgent.addNotificationSlot(mySlot).then(() => {
  console.log("addNotificationSlot promise");
});

reminderAgent.removeNotificationSlot(deprecated)

removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback<void>): void

Removes a notification slot of a specified type. This API uses an asynchronous callback to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.removeNotificationSlot.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
slotTypenotification.SlotTypeYesType of the reminder notification slot to remove.
callbackAsyncCallback<void>YesCallback used to return the result.

Example

import notification from '@ohos.notification'
import { BusinessError } from '@ohos.base';

reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err: BusinessError, data: void) => {
  console.log("removeNotificationSlot callback");
});

reminderAgent.removeNotificationSlot(deprecated)

removeNotificationSlot(slotType: notification.SlotType): Promise<void>

Removes a notification slot of a specified type. This API uses a promise to return the result.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.removeNotificationSlot.

System capability: SystemCapability.Notification.ReminderAgent

Parameters

NameTypeMandatoryDescription
slotTypenotification.SlotTypeYesType of the reminder notification slot to remove.

Return value

TypeDescription
Promise<void>Promise used to return the result.

Example

import notification from '@ohos.notification'

reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() => {
    console.log("removeNotificationSlot promise");
});

ActionButtonType(deprecated)

Enumerates button types.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ActionButtonType.

System capability: SystemCapability.Notification.ReminderAgent

NameValueDescription
ACTION_BUTTON_TYPE_CLOSE0Button for closing the reminder.
ACTION_BUTTON_TYPE_SNOOZE1Button for snoozing the reminder.

ReminderType(deprecated)

Enumerates reminder types.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ReminderType.

System capability: SystemCapability.Notification.ReminderAgent

NameValueDescription
REMINDER_TYPE_TIMER0Countdown reminder.
REMINDER_TYPE_CALENDAR1Calendar reminder.
REMINDER_TYPE_ALARM2Alarm reminder.

ActionButton(deprecated)

Defines a button displayed in the reminder notification.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ActionButton.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
titlestringYesText on the button.
typeActionButtonTypeYesButton type.

WantAgent(deprecated)

Sets the package and ability that are redirected to when the reminder notification is clicked.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.WantAgent.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
pkgNamestringYesName of the HAP that is redirected to when the reminder notification is clicked.
abilityNamestringYesName of the ability that is redirected to when the reminder notification is clicked.

MaxScreenWantAgent(deprecated)

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.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.MaxScreenWantAgent.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
pkgNamestringYesName of the HAP that is automatically started when the reminder arrives and the device is not in use.
abilityNamestringYesName of the ability that is automatically started when the reminder arrives and the device is not in use.

ReminderRequest(deprecated)

Defines the reminder to publish.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ReminderRequest.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
reminderTypeReminderTypeYesType of the reminder.
actionButtonActionButtonNoButton displayed in the reminder notification. (The parameter is optional. Up to two buttons are supported.)
wantAgentWantAgentNoInformation about the ability that is redirected to when the notification is clicked.
maxScreenWantAgentMaxScreenWantAgentNoInformation about the ability that is automatically started when the reminder arrives. If the device is in use, a notification will be displayed.
ringDurationnumberNoRinging duration, in seconds. The default value is 1.
snoozeTimesnumberNoNumber of reminder snooze times. The default value is 0.
timeIntervalnumberNoReminder snooze interval, in seconds. The default value is 0.
titlestringNoReminder title.
contentstringNoReminder content.
expiredContentstringNoContent to be displayed after the reminder expires.
snoozeContentstringNoContent to be displayed when the reminder is snoozing.
notificationIdnumberNoNotification ID used by the reminder. If there are reminders with the same notification ID, the later one will overwrite the earlier one.
slotTypenotification.SlotTypeNoType of the slot used by the reminder.

ReminderRequestCalendar(deprecated)

Defines a reminder for a calendar event.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ReminderRequestCalendar.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
dateTimeLocalDateTimeYesReminder time.
repeatMonthsArray<number>NoMonth in which the reminder repeats.
repeatDaysArray<number>NoDate on which the reminder repeats.

ReminderRequestAlarm(deprecated)

Defines a reminder for an alarm.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ReminderRequestAlarm.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
hournumberYesHour portion of the reminder time.
minutenumberYesMinute portion of the reminder time.
daysOfWeekArray<number>NoDays of a week when the reminder repeats. The value ranges from 1 to 7, corresponding to the data from Monday to Sunday.

ReminderRequestTimer(deprecated)

Defines a reminder for a scheduled timer.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.ReminderRequestTimer.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
triggerTimeInSecondsnumberYesNumber of seconds in the countdown timer.

LocalDateTime(deprecated)

Sets the time information for a calendar reminder.

NOTE

This API is supported since API version 7 and deprecated since API version 9. You are advised to use reminderAgentManager.LocalDateTime.

System capability: SystemCapability.Notification.ReminderAgent

NameTypeMandatoryDescription
yearnumberYesYear.
monthnumberYesMonth.
daynumberYesDate.
hournumberYesHour.
minutenumberYesMinute.
secondnumberNoSecond.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/b5a90ac9d47c43a1b43be4ce245e50ec