当设备关闭并再次打开时,闹钟在 Android 中不起作用
我已经在 Android 中设置了闹钟来提醒我,当设备打开时它正在工作。但是当我关闭设备并再次打开时,提醒警报不起作用。你们能建议我如何解决这个问题吗?
我的代码看起来像这样,
Intent myIntent = new Intent(getApplicationContext(), serviceclass.class);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
CONST+id, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calender = Calendar.getInstance();
calender.setTimeInMillis(System.currentTimeMillis());
calender.set(Calendar.HOUR_OF_DAY, hours);
calender.set(Calendar.MINUTE, ireminder.getMin());
calender.set(Calendar.SECOND, 0);
calender.set(Calendar.MILLISECOND, 0);
calender.set(Calendar.DAY_OF_WEEK, day);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calender.getTimeInMillis(), 7 * AlarmManager.INTERVAL_DAY, pendingIntent);
I have set the alarm to remind me in android it is working when the device is on. But when i switch off the device and again on that reminder alarm is not working. Can you guys please suggest me how can solve this problem?
My code looks like this,
Intent myIntent = new Intent(getApplicationContext(), serviceclass.class);
PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
CONST+id, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar calender = Calendar.getInstance();
calender.setTimeInMillis(System.currentTimeMillis());
calender.set(Calendar.HOUR_OF_DAY, hours);
calender.set(Calendar.MINUTE, ireminder.getMin());
calender.set(Calendar.SECOND, 0);
calender.set(Calendar.MILLISECOND, 0);
calender.set(Calendar.DAY_OF_WEEK, day);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calender.getTimeInMillis(), 7 * AlarmManager.INTERVAL_DAY, pendingIntent);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重新启动后警报将被清除。
您可以做的是
REBOOT_COMPLETED
- 事件请参阅 API:“注册的警报在设备休眠时保留(并且可以选择在该时间段内关闭时唤醒设备),但如果关闭并重新启动,则会被清除。” - http://developer.android.com/reference/android/app/AlarmManager。 html
Alarms will be cleared on reboot.
What you can do is
REBOOT_COMPLETED
-EventSee API: "Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted." - http://developer.android.com/reference/android/app/AlarmManager.html
一个 OnBootReceiver 类
创建
在您的活动清单中
Create a class OnBootReceiver
inside manifest
inside your activity