闹钟在安卓上不起作用?
我被一些我认为非常琐碎的事情所困扰。 基本上,我正在为未来的某个特定时刻安排闹钟:
Intent contentIntent = new Intent(this, AlarmReceiver.class);
PendingIntent theappIntent = PendingIntent.getService(Main.this, 0,contentIntent, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, hour,minute);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), theappIntent);
在移动设备持续开启的情况下工作正常。 我的问题是手机重启后没有触发警报 并在预期时间打开。 有什么我错过的吗?我应该做一些额外的工作来保持警惕吗 重启后安排?
I get stuck with something that , I guess , is very trivial.
Basically I am scheduling alarm for a given moment in the future :
Intent contentIntent = new Intent(this, AlarmReceiver.class);
PendingIntent theappIntent = PendingIntent.getService(Main.this, 0,contentIntent, 0);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, hour,minute);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), theappIntent);
works fine while mobile is constantly on.
My problem is that alarm is not triggered after mobile is restarted
and is TURNED ON on the expected time.
Is there something I missed? Should I do some extra work to keep alarm
scheduled after restart?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当设备启动时,您必须重置警报。
当设备启动并重置警报时,您缺少检测应用程序。所以下面是在清单中编写的代码
同时创建一个 BroadcastReceiver 来接收启动完成的意图
You have to reset the alarm when device get boot.
You are missing to detect the app when device boot and reset the alarm..so below is code written in manifest
Also create a BroadcastReceiver to receive the boot completed intent
您应该添加一个接收器来监听 android.intent.action.BOOT_COMPLETED 并从那里启动闹钟。
You should add an receiver For listening android.intent.action.BOOT_COMPLETED and start your alarm from there.