18

I want to use and alarmManager that sets a repeating alarm to go off on the hour, every hour. I know how to set a repeating alarm every hour but not how to actually set it from the top of the hour, I need to know this value for the 'whatTime' variable below.

AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, whatTime, 1*60*60*1000, operation);

Also I want to be able to set a flag that for e.g. - if the time happens to be between 4 and 8 in the daytime, perform some operations, otherwise don't bother.
So I really need to know how to find out the hour of the day, can anyone tell me how to do this? Many thanks

bobby123
  • 1,006
  • 4
  • 14
  • 24

1 Answers1

57

Try:

int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
Yahel
  • 8,522
  • 2
  • 24
  • 32
Matthew
  • 44,826
  • 10
  • 98
  • 87
  • That sorts the second thing I want to use it for and pretty sure it should work for my alarmManager too if i get Calendar.MINUTE I can work out how long til the next top of hour and set repeating alarms from then, thanks a lot man! – bobby123 Mar 08 '11 at 11:57