我想创建一个每日闹钟,定期重复而不中断。我尝试使用 android_alarm_manager 来完成此任务。使用这个,我可以通过在闹钟不再工作后设置一周来创建定期闹钟。我需要每天闹钟,而不仅仅是 7 天
静态未来计划可重复(警报警报)异步{
for (int weekday = 0; weekday < 7; ++weekday) {
if (alarm.weekday[weekday]) {
final callbackId = alarm.callbackIdOf(weekday);
final time = alarm.timeOfDay.toComingDateTimeAt(weekday);
await _oneShot(callbackId, time);
}
}
}
> static Future scheduleRepeatable(Alarm alarm) async { final alarmManager = await getSystemService(AlarmManager); final interval
> = alarm.repeatInterval.inMilliseconds;
>
> for (int weekday = 0; weekday < 7; ++weekday) {
> if (alarm.weekday[weekday]) {
> final triggerTime = alarm.timeOfDay.toComingDateTimeAt(weekday);
> await alarmManager.setInexactRepeating(
> RTC_WAKEUP,
> triggerTime.millisecondsSinceEpoch,
> interval,
> alarm.callbackIdOf(weekday),
> );
> } } }