我创建了简单的闹钟应用。它工作正常但是,如果我手动更改设备的时间,那么我的闹钟不起作用....
这是我的代码:
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);
有什么建议吗?
答案 0 :(得分:7)
[将评论的答案添加到此处]
你需要添加一个接收器来重新设置闹钟..日期和时区更改然后警报重置,所以使用此
<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>