
回复
基于鸿蒙代理提醒与延迟任务,打造低耗稳定的提醒系统,核心逻辑如下:
类型 | 核心场景 | 关键参数 | 代码示例片段 |
---|---|---|---|
倒计时提醒 | 会议倒计时、烹饪定时 | triggerTimeInSeconds |
publishReminder({type:'TIMER', trigger:300}) |
日历提醒 | 生日、还款、会议预约 | dateTime /repeatMonths |
dateTime:{year:2024, month:12, day:31} |
闹钟提醒 | 每日起床、服药提醒 | hour /daysOfWeek |
daysOfWeek:[1,2,3,4,5] (工作日) |
统一发布接口
function scheduleReminder(reminder: ReminderRequestBase) {
reminderAgentManager.publishReminder(reminder).then(id => {
console.log('提醒ID:', id); // 存储ID用于管理
});
}
应用活跃程度 | 提醒最小间隔 | 适用场景 |
---|---|---|
活跃(如社交) | 2小时 | 即时消息通知 |
常用(如工具) | 24小时 | 定期数据同步 |
极少使用 | 48小时 | 低频清理提醒 |
if (level < 15) cancelAllReminders();
const reminderSlot = {
slotId: 'alarm_channel',
name: '重要提醒',
importance: 'HIGH', // 弹窗+响铃+呼吸灯
vibrationPattern: [100, 200], // 振动节奏(毫秒)
ledColor: '#FF5733'
};
notificationManager.addNotificationSlot(reminderSlot);
const buttons = [
{
title: '立即处理',
type: 'ACTION',
want: { abilityName: 'TaskDetailAbility' } // 点击跳转
},
{
title: '1小时后提醒',
type: 'SNOOZE',
snoozeTime: 3600 // 延时执行
}
];
邮件模板速记:
申请用于「健身助手」的每日运动提醒,用户可设置每周3次,点击通知直达训练计划。
graph LR
A[用户设置提醒] --> B{类型判断}
B -->|倒计时| C[TIMER类型代理提醒]
B -->|日历事件| D[CALENDAR类型代理提醒]
B -->|每日闹钟| E[ALARM类型代理提醒]
CDE --> F[系统分组调度]
F --> G[动态资源适配]
G --> H[通知渠道展示]