| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| AppScope/ | 06-May-2025 | - | 37 | 34 | ||
| entry/ | 06-May-2025 | - | 3,807 | 3,545 | ||
| hvigor/ | 06-May-2025 | - | 22 | 21 | ||
| screenshots/devices/ | 06-May-2025 | - | ||||
| .gitignore | D | 06-May-2025 | 79 | 6 | 6 | |
| README_zh.md | D | 06-May-2025 | 8.5 KiB | 125 | 87 | |
| build-profile.json5 | D | 06-May-2025 | 1 KiB | 42 | 41 | |
| hvigorfile.js | D | 06-May-2025 | 777 | 17 | 1 | |
| hvigorw | D | 06-May-2025 | 2.1 KiB | 64 | 28 | |
| hvigorw.bat | D | 06-May-2025 | 2 KiB | 73 | 56 | |
| oh-package.json5 | D | 06-May-2025 | 809 | 27 | 25 | |
| ohosTest.md | D | 06-May-2025 | 1.8 KiB | 24 | 21 |
README_zh.md
1# 后台代理提醒 2 3### 介绍 4 5本示例通过使用后台代理提醒的能力,创建闹钟、日历、计时器三种类型的定时提醒,保证应用被冻结或退出时,计时和弹出提醒的功能可以被后台系统服务代理。 6 7本示例使用 [Tabs组件](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-ts/ts-container-tabs.md) 进行应用布局,使用 [Canvas组件](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/arkui-js/js-components-canvas-canvas.md) 绘制时钟、倒计时,使用 [后台代理提醒](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-backgroundtasks-kit/js-apis-reminderAgentManager.md) 发布后台代理提醒,使用 [振动](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md) 设置振动效果。 8 9### 效果预览 10 11| 闹钟 | 日历 | 计时器 | 12|---------------------------------------------|------------------------------------------|---------------------------------------| 13|  |  |  | 14 15使用说明: 16 171.点击**闹钟**、**日历**、**计时器**三个按钮切换不同视图。 18 192.1.点击闹钟页面右上角**+**按钮选择闹钟提醒时间添加闹钟提醒。 20 212.2.点击闹钟列表中可设置闹钟重复日期、延迟次数、延迟时长、是否震动、响铃音乐。 22 232.3.点击闹钟列表右侧开关按钮,可关闭或打开当前提醒。 24 252.4.右滑当前闹钟列表可选择删除当前提醒。 26 273.1.点击点击日历页面右上角**+**按钮选择日期提醒时间添加日期提醒。 28 293.2.点击日期列表中可设置日历提醒当天具体提醒时间、是否振动、是否响铃。 30 313.3.点击日历列表右侧开关按钮,可关闭或打开当前提醒。 32 333.4.右滑当前日历列表可选择删除当前提醒。 34 354.1.滑动计时器时间选项设置计时器时间。 36 374.2.点击**开始**按钮,开始当前计时器并设置倒计时后台提醒。 38 394.3.点击**重置**按钮,取消当前计时器提醒并重新设置计时器。 40 414.4.点击**暂停**按钮,暂停当前计时器提醒与倒计时;再次点击按钮恢复计时器提醒与计时器计时。 42 43### 工程目录 44``` 45entry/src/main/ets/ 46|---Application 47| |---MyAbilityStage.ts 48|---common 49| |---Constant.ets // 数据初始化 50| |---Reminder.ets // 定义数据类型 51|---MainAbility 52| |---MainAbility.ts 53|---pages 54| |---Index.ets // 首页 55| |---alarmClock 56| | |---AlarmClock.ets // 闹钟页面 57| | |---AlarmClockSetting.ets // 设置闹钟 58| | |---DrawClock.ets // 绘制闹钟 59| |---calendar 60| | |---Calendar.ets // 日历页面 61| | |---CalendarSetting.ets // 设置日历 62| |---timer 63| | |---SelectTime.ets // 计时器页面 64| | |---Timer.ets // 计时 65|---util 66| |---AlarmClockReminder.ets // 闹钟管理 67| |---AudioPlayer.ets // 音频播放 68| |---CalendarReminder.ets // 日历管理 69| |---PreferencesDataManager.ets // 数据管理 70| |---TimeConversion.ets // 时间转换 71| |---Logger.ts // 日志打印 72``` 73### 具体实现 74 75* 该示例分为闹钟,日历,计时器三个模块 76 * 闹钟模块 77 * 使用Canvas组件绘制一个闹钟,SlotType方法获取对应的系统能力内容类型,addNotificationSlot方法添加一个NotificationSlot,ReminderRequestAlarm方法获取闹钟实例对象,用于设置提醒的时间,ReminderType方法设置提醒的类型,ActionButtonType方法设置按钮的类型,VibratorStopMode方法停止的振动。 78 * 源码链接:[AlarmClockReminder.ets](entry/src/main/ets/util/AlarmClockReminder.ets),[Reminder.ets](entry/src/main/ets/common/Reminder.ets),[AlarmClock.ets](entry/src/main/ets/pages/alarmClock/AlarmClock.ets),[Constant.ets](entry/src/main/ets/common/Constant.ets) 79 * 接口参考:[@ohos.notification](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-notification-kit/js-apis-notification.md),[@ohos.reminderAgent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-backgroundtasks-kit/js-apis-reminderAgent.md),[@ohos.vibrator](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md) 80 81 * 日历模块 82 * 使用SlotType方法获取对应的系统能力内容类型,ReminderRequestCalendar方法获取日历实例对象,用于设置提醒的时间,ReminderType方法设置提醒的类型,ActionButtonType方法设置按钮的类型,VibratorStopMode方法停止的振动。 83 * 源码链接:[CalendarReminder.ets](entry/src/main/ets/util/CalendarReminder.ets),[Reminder.ets](entry/src/main/ets/common/Reminder.ets),[Calendar.ets](entry/src/main/ets/pages/calendar/Calendar.ets),[Constant.ets](entry/src/main/ets/common/Constant.ets) 84 * 接口参考:[@ohos.notification](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-notification-kit/js-apis-notification.md),[@ohos.reminderAgent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-backgroundtasks-kit/js-apis-reminderAgent.md),[@ohos.vibrator](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md) 85 86 * 计时器模块 87 * 使用SlotType方法获取对应的系统能力内容类型,addNotificationSlot方法添加一个NotificationSlot,ReminderRequestTimer方法获取倒计时实例对象,用于设置提醒的时间,ReminderType方法设置提醒的类型,ActionButtonType方法设置按钮的类型,VibratorStopMode方法停止的振动。 88 * 源码链接:[Timer.ets](entry/src/main/ets/pages/timer/Timer.ets),[Reminder.ets](entry/src/main/ets/common/Reminder.ets),[Constant.ets](entry/src/main/ets/common/Constant.ets) 89 * 接口参考:[@ohos.notification](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-notification-kit/js-apis-notification.md),[@ohos.reminderAgent](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-backgroundtasks-kit/js-apis-reminderAgent.md),[@ohos.vibrator](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-sensor-service-kit/js-apis-vibrator.md) 90 91### 相关权限 92 931.允许该应用使用后台代理提醒 [ohos.permission.PUBLISH_AGENT_REMINDER](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionpublish_agent_reminder) 94 952.允许应用控制马达振动 [ohos.permission.VIBRATE](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionvibrate) 96 973.允许应用读取用户外部存储中的媒体文件信息 [ohos.permission.READ_MEDIA](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_media) 98 994.允许应用读取日历信息 [ohos.permission.READ_CALENDAR](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionread_calendar) 100 1015.允许应用添加、移除或更改日历活动 [ohos.permission.WRITE_CALENDAR](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionwrite_calendar) 102 103### 依赖 104 105不涉及。 106 107### 约束与限制 108 1091.本示例仅支持标准系统上运行,支持设备:RK3568。 110 1112.本示例已适配API version 12版本SDK,版本号:5.0.0.70。 112 1133.本示例需要使用DevEco Studio 3.1 Beta2 (Build Version: 3.1.0.400, built on April 7, 2023)及以上版本才可编译运行。 114 115### 下载 116 117如需单独下载本工程,执行如下命令: 118``` 119git init 120git config core.sparsecheckout true 121echo code/BasicFeature/TaskManagement/ReminderAgentManager/ > .git/info/sparse-checkout 122git remote add origin https://gitee.com/openharmony/applications_app_samples.git 123git pull origin master 124 125```