Just modify the code alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent) in AndroidAlarmService class to alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, pendingIntent).
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(AndroidAlarmService.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(AndroidAlarmService.this, 0, myIntent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 10);
//alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, pendingIntent);
Toast.makeText(AndroidAlarmService.this, "Start Alarm", Toast.LENGTH_LONG).show();
}});
public void setRepeating (int type, long triggerAtTime, long interval, PendingIntent operation), like set(int, long, PendingIntent), except you can also supply a rate at which the alarm will repeat.
Related article:
- App Widget using Alarm Manager
Hi,
ReplyDeleteI am newby to android development. I am developing an alarm application in android,
I need to create a single repeat alarm which will repeat in selected multiple days in a week like ,if i select every monday ,every tuesday,every wednesday then the created alarm should repeat in those three days in every week until it will be canceled.
Can you help me in this?
thanks in advance
s.avunoori
sathya.sri69@gmail.com
hello sathya,
ReplyDeleteI think you can set the first alarm fire using alarmManager.set, then set the subsequence using alarmManager.setRepeating in the first fire.
Hi,
ReplyDeleteI need to display the Notification based on the time from the database (Eg: 10AM,12 AM,etc.. )even if the app is not running.. Database will contain many dates with times. If the time reaches i need to display the notificaiton.How can I do that. Lease provide any samples or suggestions
Hi, is this alarm supposed to work even if the device is powered off?
ReplyDeleteI'm using a tablet, Coby Kyros MID 7016-4G, and it doesn't turn on...
hi,
ReplyDeletei tried using this: alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, displayIntent);
however it repeat like every 5 sec(think so).. but i don't want that..
what i want is repeat the same time
everyday.. means i set the alarm once, and it will alarm the same time everyday eg. alarm clock
is there anything to do with 5*1000 on the code?
Nur Adilah you want the alarm to repeat every 24h, so you should set the repeating time to:
ReplyDelete24*3600*1000
(24 hours, every hour with 3600 secs, 1000 times because you have to specify the repeating time in milis)
I think that should work :)
i tried using this: alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 5*1000, displayIntent);
ReplyDeleteWhy i cannot cancel the alarm ?
The system keep on toast message.
Anyone can help on this ?
Regards,
Chua
chuasw23@gmail.com
Thanks. It saved me a lot of time.
ReplyDeleteI want to make an alarm which rings at 9:30 pm everynight. And also displays a message saying "Have Dinner" .
ReplyDeleteCan u please tell me how to do it ? Its kinda urgent. Thanks :)
anamikabarbie@yahoo.co.in
please read Create alarm set on a specified time, using AlarmManager and BroadcastReceiver.
ReplyDeleteHi Thanks a million. I'm a beginner level for android and It is very helpful for me.
ReplyDelete