广播接收器中的 Android AlarmManager
我有广播接收器,该广播接收器应安排闹钟。
通常我会这样做
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC, time, myPendingIntent);
问题是 getSystemService 仅在活动中的广播接收器中不可用。我在这里该怎么做呢?
谢谢,A.
I have braodcastreceiver, that broadcast receiver shall schedule an alarm.
Usually I would do
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC, time, myPendingIntent);
The problem is that getSystemService is not available in a Broadcast receiver only in an Activty. How would I do it here?
Thanks, A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AndyAndroid,
getSystemService()
是Context
的一部分。您需要保存在onReceive()
方法中收到的Context
,如下所示...然后...在您调用
getSystemService()
的地方你用...AndyAndroid,
getSystemService()
is part of theContext
. You will need to save theContext
you receive in youronReceive()
method like so...Then..where you call
getSystemService()
you use...