后臺代理提醒
本模塊提供后臺代理提醒的能力。
開發應用時,開發者可以調用后臺提醒發布的接口創建定時提醒,包括倒計時、日歷、鬧鐘三種提醒類型。使用后臺代理提醒能力后,應用可以被凍結或退出,計時和彈出提醒的功能將被后臺系統服務代理。
說明: 本模塊首批接口從API version 7開始支持。后續版本的新增接口,采用上角標單獨標記接口的起始版本。
導入模塊
import reminderAgent from'@ohos.reminderAgent';
開發前請熟悉鴻蒙開發指導文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md]點擊或者復制轉到。
reminderAgent.publishReminder
publishReminder(reminderReq: ReminderRequest, callback: AsyncCallback): void
發布一個后臺代理提醒,使用callback方式實現異步調用。
需要權限 : ohos.permission.PUBLISH_AGENT_REMINDER
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
reminderReq | [ReminderRequest] | 是 | 需要發布的提醒實例。 |
callback | AsyncCallback | 是 | 異步回調,返回當前發布的提醒的reminderId。 |
示例 :
let timer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10
}
reminderAgent.publishReminder(timer, (err, reminderId) = > {
console.log("callback, reminderId = " + reminderId);
});
reminderAgent.publishReminder
publishReminder(reminderReq: ReminderRequest): Promise
發布一個后臺代理提醒,使用Promise方式實現異步調用。
需要權限 : ohos.permission.PUBLISH_AGENT_REMINDER
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
reminderReq | [ReminderRequest] | 是 | 需要發布的提醒實例。 |
返回值 :
類型 | 說明 |
---|---|
Promise | 返回提醒的reminderId。 |
示例 :
let timer = {
reminderType: reminderAgent.ReminderType.REMINDER_TYPE_TIMER,
triggerTimeInSeconds: 10
}
reminderAgent.publishReminder(timer).then((reminderId) = > {
console.log("promise, reminderId = " + reminderId);
});
reminderAgent.cancelReminder
cancelReminder(reminderId: number, callback: AsyncCallback): void
取消指定id的提醒,使用callback方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
reminderId | number | 是 | 目標reminder的id號。 |
callback | AsyncCallback | 是 | 異步回調。 |
示例 :
reminderAgent.cancelReminder(1, (err, data) = > {
console.log("cancelReminder callback");
});
reminderAgent.cancelReminder
cancelReminder(reminderId: number): Promise
取消指定id的提醒,使用Promise方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
reminderId | number | 是 | 目標reminder的id號。 |
返回值 :
類型 | 說明 |
---|---|
Promise | Promise類型異步回調。 |
示例 :
reminderAgent.cancelReminder(1).then(() = > {
console.log("cancelReminder promise");
});
reminderAgent.getValidReminders
getValidReminders(callback: AsyncCallback>): void
獲取當前應用已設置的所有有效(未過期)的提醒,使用callback方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback> | 是 | 異步回調,返回當前應用已設置的所有有效(未過期)的提醒。 |
示例 :
reminderAgent.getValidReminders((err, reminders) = > {
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);
for (let j = 0; j < reminders[i].actionButton.length; j++) {
console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title);
console.log("getValidReminders, actionButton.type = " + reminders[i].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
getValidReminders(): Promise>
獲取當前應用已設置的所有有效(未過期)的提醒,使用Promise方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
返回值 :
類型 | 說明 |
---|---|
Promise> | 返回當前應用已設置的所有有效(未過期)的提醒。 |
示例 :
reminderAgent.getValidReminders().then((reminders) = > {
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);
for (let j = 0; j < reminders[i].actionButton.length; j++) {
console.log("getValidReminders, actionButton.title = " + reminders[i].actionButton[j].title);
console.log("getValidReminders, actionButton.type = " + reminders[i].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
cancelAllReminders(callback: AsyncCallback): void
取消當前應用所有的提醒,使用callback方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
callback | AsyncCallback | 是 | 異步回調。 |
示例 :
reminderAgent.cancelAllReminders((err, data) = >{
console.log("cancelAllReminders callback")
})
reminderAgent.cancelAllReminders
cancelAllReminders(): Promise
取消當前應用所有的提醒,使用Promise方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
返回值 :
類型 | 說明 |
---|---|
Promise | Promise類型異步回調。 |
示例 :
reminderAgent.cancelAllReminders().then(() = > {
console.log("cancelAllReminders promise")
})
reminderAgent.addNotificationSlot
addNotificationSlot(slot: NotificationSlot, callback: AsyncCallback): void
添加一個NotificationSlot,使用callback方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
slot | [NotificationSlot] | 是 | notification slot實例,僅支持設置其type屬性。 |
callback | AsyncCallback | 是 | 異步回調。 |
示例 :
import notification from '@ohos.notification'
let mySlot = {
type: notification.SlotType.SOCIAL_COMMUNICATION
}
reminderAgent.addNotificationSlot(mySlot, (err, data) = > {
console.log("addNotificationSlot callback");
});
reminderAgent.addNotificationSlot
addNotificationSlot(slot: NotificationSlot): Promise
添加一個NotificationSlot,使用Promise方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
slot | [NotificationSlot] | 是 | notification slot實例,僅支持設置其type屬性。 |
返回值 :
類型 | 說明 |
---|---|
Promise | Promise類型異步回調。 |
示例 :
import notification from '@ohos.notification'
let mySlot = {
type: notification.SlotType.SOCIAL_COMMUNICATION
}
reminderAgent.addNotificationSlot(mySlot).then(() = > {
console.log("addNotificationSlot promise");
});
reminderAgent.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType, callback: AsyncCallback): void
刪除目標NotificationSlot,使用callback方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
slotType | [notification.SlotType] | 是 | 目標notification slot的類型。 |
callback | AsyncCallback | 是 | 異步回調。 |
示例 :
import notification from '@ohos.notification'
reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION, (err, data) = > {
console.log("removeNotificationSlot callback");
});
reminderAgent.removeNotificationSlot
removeNotificationSlot(slotType: notification.SlotType): Promise
刪除目標NotificationSlot,使用Promise方式實現異步調用。
系統能力 : SystemCapability.Notification.ReminderAgent
參數 :
參數名 | 類型 | 必填 | 說明 |
---|---|---|---|
slotType | [notification.SlotType] | 是 | 目標notification slot的類型。 |
返回值 :
類型 | 說明 |
---|---|
Promise | Promise類型異步回調。 |
示例 :
import notification from '@ohos.notification'
reminderAgent.removeNotificationSlot(notification.SlotType.CONTENT_INFORMATION).then(() = > {
console.log("removeNotificationSlot promise");
});
ActionButtonType
按鈕的類型。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 默認值 | 說明 |
---|---|---|
ACTION_BUTTON_TYPE_CLOSE | 0 | 表示關閉提醒的按鈕。 |
ACTION_BUTTON_TYPE_SNOOZE | 1 | 表示延遲提醒的按鈕。 |
ReminderType
提醒的類型。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 默認值 | 說明 |
---|---|---|
REMINDER_TYPE_TIMER | 0 | 表示提醒類型:倒計時。 |
REMINDER_TYPE_CALENDAR | 1 | 表示提醒類型:日歷。 |
REMINDER_TYPE_ALARM | 2 | 表示提醒類型:鬧鐘。 |
ActionButton
用于設置彈出的提醒通知信息上顯示的按鈕類型和標題。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
title | string | 是 | 按鈕顯示的標題。 |
type | [ActionButtonType] | 是 | 按鈕的類型。 |
WantAgent
點擊提醒通知后跳轉的目標ability信息。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
pkgName | string | 是 | 指明點擊提醒通知欄后跳轉的目標hap包名。 |
abilityName | string | 是 | 指明點擊提醒通知欄后跳轉的目標ability名稱。 |
MaxScreenWantAgent
提醒到達時自動拉起的目標ability信息。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
pkgName | string | 是 | 指明提醒到達時自動拉起的目標hap包名(如果設備在使用中,則只彈出通知橫幅框)。 |
abilityName | string | 是 | 指明提醒到達時自動拉起的目標ability名(如果設備在使用中,則只彈出通知橫幅框)。 |
ReminderRequest
提醒實例對象,用于設置提醒類型、響鈴時長等具體信息。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
reminderType | ReminderType | 是 | 指明提醒類型。 |
actionButton | [ActionButton?, ActionButton?] | 否 | 彈出的提醒通知欄中顯示的按鈕(參數可選,支持0/1/2個按鈕)。 |
wantAgent | WantAgent | 否 | 點擊通知后需要跳轉的目標ability信息。 |
maxScreenWantAgent | MaxScreenWantAgent | 否 | 提醒到達時跳轉的目標包。如果設備正在使用中,則彈出一個通知框。 |
ringDuration | number | 否 | 指明響鈴時長。 |
snoozeTimes | number | 否 | 指明延遲提醒次數。 |
timeInterval | number | 否 | 執行延遲提醒間隔。 |
title | string | 否 | 指明提醒標題。 |
content | string | 否 | 指明提醒內容。 |
expiredContent | string | 否 | 指明提醒過期后需要顯示的內容。 |
snoozeContent | string | 否 | 指明延遲提醒時需要顯示的內容。 |
notificationId | number | 否 | 指明提醒使用的通知的id號,相同id號的提醒會覆蓋。 |
slotType | [notification.SlotType] | 否 | 指明提醒的slot類型。 |
ReminderRequestCalendar
ReminderRequestCalendar extends ReminderRequest
日歷實例對象,用于設置提醒的時間。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
dateTime | [LocalDateTime] | 是 | 指明提醒的目標時間。 |
repeatMonths | Array | 否 | 指明重復提醒的月份。 |
repeatDays | Array | 否 | 指明重復提醒的日期。 |
ReminderRequestAlarm
ReminderRequestAlarm extends ReminderRequest
鬧鐘實例對象,用于設置提醒的時間。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
hour | number | 是 | 指明提醒的目標時刻。 |
minute | number | 是 | 指明提醒的目標分鐘。 |
daysOfWeek | Array | 否 | 指明每周哪幾天需要重復提醒。 |
ReminderRequestTimer
ReminderRequestTimer extends ReminderRequest
倒計時實例對象,用于設置提醒的時間。
系統能力 :SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
---|---|---|---|
triggerTimeInSeconds | number | 是 | 指明倒計時的秒數。 |
LocalDateTime
用于日歷類提醒設置時指定時間信息。
系統能力 :以下各項對應的系統能力均為SystemCapability.Notification.ReminderAgent
名稱 | 參數類型 | 必填 | 說明 |
---|---|---|---|
year | number | 是 | 年 |
month | number | 是 | 月 |
day | number | 是 | 日 |
hour | number | 是 | 時 |
minute | number | 是 | 分 |
second | number | 否 | 秒 |
-
HarmonyOS
+關注
關注
79文章
2005瀏覽量
31691 -
OpenHarmony
+關注
關注
26文章
3795瀏覽量
17661 -
鴻蒙OS
+關注
關注
0文章
190瀏覽量
4811
發布評論請先 登錄
相關推薦
鴻蒙原生應用/元服務開發-通知添加行為意圖
鴻蒙原生應用/元服務開發-代理提醒說明(一)
鴻蒙原生應用/元服務開發-代理提醒開發步驟(二)
基于ArkTS語言的OpenHarmony APP應用開發:公共事件的訂閱和發布
HarmonyOS應用開發-公共事件處理
請問鴻蒙智能穿戴設備如何保持后臺任務定時獲取網絡數據?
HarmonyOS后臺任務管理開發指南上線!
鴻蒙原生應用/元服務開發-Stage模型能力接口(四)
鴻蒙開發接口Ability框架:【@ohos.ability.wantConstant (wantConstant)】

鴻蒙開發接口公共事件與通知:【FFI能力(Node-API)】

基于ArkTS語言的OpenHarmony APP應用開發:公共事件的訂閱和發布

評論