我创建了简单的报警应用程序.它工作正常但是,如果我手动更改设备的时间,那么我的闹钟不起作用….
这是我的代码:
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,intent,0); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,c.getTimeInMillis(),pendingIntent);
有什么建议吗?
解决方法
[将评论的答案添加到此处]
你需要添加一个接收器来重新设置警报..在日期和时区更改然后警报重置,所以使用它
<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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。