0 purchases
nova alarm plugin
nova_alarm_plugin :^0.1.0 #
设置闹钟定时器和日历提醒的插件.
使用日历提醒功能 #
Android部分 #
1 申请权限
NovaAlarmPlugin.requestCalendarPermission()
项目中注册
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
copied to clipboard
2 插入日历提醒
通过名称添加事件
var now = new DateTime.now();
var dateTime = new DateTime(now.year,now.month,now.day+3,now.hour,now.minute);
var beginTime = dateTime.millisecondsSinceEpoch;
await NovaAlarmPlugin.insertCalenderEvent(beginTime, "提醒名", "提醒内容",3,repeatDay: true); 3代表提前提醒天数;
repeateDay:bool 开启重复提醒 (repeateDay为true时,repeateValue有效)
repeateValue: int 重复提醒频率 例如每天提醒一次 repeatevalue =1
copied to clipboard
3 删除日历提醒
通过名称删除事件(建议 删除后延时插入新的日历,否则可能导致日历添加失败)
NovaAlarmPlugin.deleteCalendarEvent("提醒名");
copied to clipboard
IOS部分 #
(暂未添加IOS日历设置部分)
使用闹钟功能 #
Android部分 #
1,闹钟权限申请
注册表添加设置闹钟权限
<uses-permission android:name="android.permission.SET_ALARM" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
copied to clipboard
2,设置闹钟
由于平台差异性,Android调用原生闹钟只能设置当前时间戳和备注信息
/// time 设置闹钟的时间戳 闹钟备注 一般闹钟生效后会自我销毁
static Future<bool> setClock(String time,
{String content}) async {
var kParams = {
"time": time,
"content": content,
};
}
copied to clipboard
3,取消闹钟
跳转到闹钟界面 需要用户手动关闭未生效的闹钟
static Future<bool> closeClock() async {
return await _channel.invokeMethod('cancelAllClock', null);
}
copied to clipboard
4,额外功能(唤醒前台service方便用户点击启动app)(前台服务)
//Android平台初始化定时器和前台Service
static Future initClockService({String title,String content}) async {
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isAndroid) {
var params = {
"title":title,
"content":content
};
await _channel.invokeMethod('initClockService',params);
}
}
copied to clipboard
IOS部分 #
IOS使用的本地推送实现闹钟提醒
setClock
requestClockPermission
isClockAvailable
closeClock
closeNotification
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.