I set an alarm with an alarm manager to start from 6pm. If it's already 6pm, I want him to start the next day at 6pm.
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Calendar calendar = Calendar.getInstance(); if(calendar.get(Calendar.HOUR_OF_DAY) < 18) { calendar.set(Calendar.HOUR, 18); calendar.set(Calendar.MINUTE, 0); } else {
I have 6 Android tablets with the same code, and some wake up at the right time, others work after a few hours. I checked the time and all matches. The documentation for AlarmManager says to use UTC time to set an alarm, but in practice I use local time, and those that work shoot at the right time. The rest shoot 4 hours before time. What am I doing wrong?
Edit: I cannot answer my question, so I installed Calendar.HOUR instead of HOUR_OF_DAY, which caused the wrong time.
source share