Skip to content Skip to sidebar Skip to footer

Unable To Set Alarm Time In Android

In my alarm application, I take time from time picker and set it in alarm manager. But the time which I set in the time picker was not set properly in alarm manager. So the alarm i

Solution 1:

I was able to replicate your problem and find why it was failing. Basically, say you were testing at "12:25" like i was, then using Calendar.HOUR of 12 and doing c.get(Calendar.HOUR_OF_DAY) was returning 0.

To change, simply use:

Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
c.set(Calendar.HOUR_OF_DAY, hourOfDay);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, 0);

i.e. remove the clear, and set HOUR_OF_DAY instead of HOUR

Post a Comment for "Unable To Set Alarm Time In Android"