设置每天特定时间重复闹钟
我尝试使用闹钟管理器在每天的特定时间运行闹钟。 我正在使用这段代码,
Intent intent = new Intent(AlarmSettings.this, AlarmService.class);
intent.putExtra("i", i);
PendingIntent mAlarmSender = PendingIntent.getService(AlarmSettings.this, Id, intent, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),Calendar.getInstance().getTimeInMillis()+(24*60*60*1000), mAlarmSender);}
问题出在 如果 cal.getTimeInMillis() 值是过去的,则警报立即运行,我不知道为什么,而当 cal.getTimeInMillis() 值是将来时,它会在当时正确运行。
我需要让它在每天的特定时间运行。
I try to use alarm manager to run alarm at specific time every day.
I am using this code
Intent intent = new Intent(AlarmSettings.this, AlarmService.class);
intent.putExtra("i", i);
PendingIntent mAlarmSender = PendingIntent.getService(AlarmSettings.this, Id, intent, 0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),Calendar.getInstance().getTimeInMillis()+(24*60*60*1000), mAlarmSender);}
the problem was in
if cal.getTimeInMillis() value is in the past the alarm run immediately, i do not know why, and when cal.getTimeInMillis() value is in the future it runs correctly at its time.
I need to make it run at specific time every day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我帮助很大,我也遇到过使用会议记录的情况,并提出了以下小修改:
This helped me a lot, I had a case where I was using minutes also and came up with the following small amendment:
看起来你对
尝试设置正确的triggerAtTime(将来)的调用 - 就像
第三个参数(间隔)显然应该是你的间隔,就像
It looks like your call to
Try to set proper triggerAtTime (in the future) - like
The third param (interval) should obviously be your interval, like