首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >android中的告警管理器

android中的告警管理器
EN

Stack Overflow用户
提问于 2011-11-14 16:57:20
回答 1查看 1.5K关注 0票数 7

我已经创建了简单的警报应用程序。它工作得很好,但是,如果我手动更改设备的时间,那么我的闹钟就不工作了……

这是我的代码:

代码语言:javascript
复制
    Calendar = Calendar.getInstance();
    //c.add(Calendar.DAY_OF_WEEK,1);
    c.set(Calendar.HOUR_OF_DAY,15);
    c.set(Calendar.MINUTE, 00);
    c.set(Calendar.SECOND, 00);
    c.set(Calendar.MILLISECOND, 0);

    Intent intent = new Intent(HomeActivity.this, MyAlarmService.class);
    pendingIntent = PendingIntent.getService(HomeActivity.this, 0, intent, 0);
    alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, c.getTimeInMillis(), pendingIntent);

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-10 13:58:42

将评论中的答案添加到此处

您需要添加一个接收器来设置警报again..on日期和时区更改,然后警报得到重置,所以使用这个

代码语言:javascript
复制
<receiver android:name=".AlarmInitReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.TIME_SET" /> <action android:name="android.intent.action.TIMEZONE_CHANGED" /> 
</intent-filter> 
</receiver>
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8119215

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档