Reputation: 33741
Trying to fire up an alarm at a specific time, like this:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR, 17);
calendar.set(Calendar.MINUTE, 54);
AlarmManager alarmManager = (AlarmManager)getContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 30*1000, mAlarmSender);
Doesn't seem to be working. I'm logging onCreate()
in my Service
and it doesn't seem to be getting called ever.
EDIT - I tried switching to calendar.set(Calendar.HOUR_OF_DAY, 17)
, which I believe is the right way to do it because that's the 24 hr hour.
But it still isn't working... ;)
EDIT It's working now. I just jumped the gun a bit. Apparently the alarm isn't 100% exact.
Upvotes: 0
Views: 1108
Reputation: 40136
Use like,
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 17);
calendar.set(Calendar.MINUTE, 54);
AlarmManager alarmManager = (AlarmManager)getContext().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 30*1000, mAlarmSender);
Upvotes: 0
Reputation: 33741
Calendar object must be set to (Calendar.HOUR_OF_DAY)
as opposed to (Calendar.HOUR)
when you're using a 24 hr hour.
Upvotes: 1