I wanted to know How I can set Alarm for a particular time. For example I want to set alarm for morning 9am daily. I googled a lot but found only the way to set alarm for a given interval only. like after 2 hours or next day.
Asked
Active
Viewed 1,781 times
1
-
This should help: http://stackoverflow.com/questions/5938213/android-alarmmanager-rtc-wakeup-vs-elapsed-realtime-wakeup – stephendnicholas May 08 '12 at 10:18
2 Answers
1
hope this code helps you
Calendar calendar = Calendar.getInstance();
//9 AM
calendar.set(Calendar.HOUR_OF_DAY, 9);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getService(context, 0, new Intent(context, YourClass.class), PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pi);
you should create BroadcastReceiver to receive intent.
read the documentation for further details

Hassy31
- 2,793
- 3
- 21
- 37
0
I googled a lot but found only the way to set alarm for a given interval only. like after 2 hours or next day.
The second parameter to setRepeating()
on AlarmManager
is when you want the alarm to go off first. Set that to be 9am tomorrow using a Calendar object, and use an RTC
or RTC_WAKEUP
alarm.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491