android - Alarm Manager to schedule an event to fire every day in different times -
i'm trying develop ramadan emsakia ,and want alarm run ever day in different
intent = new intent(this, oneshotalarm.class); i.addflags(intent.flag_activity_new_task);
alarmmanager alarmmgr0 = (alarmmanager)getsystemservice(context.alarm_service); pendingintent pi = pendingintent.getbroadcast(this, 0, i, pendingintent.flag_update_current); calendar timeoff0 = calendar.getinstance(); timeoff0.set(calendar.year, 2013); timeoff0.set(calendar.month, 6); timeoff0.set(calendar.day_of_month,1 ); timeoff0.set(calendar.hour_of_day, 8); timeoff0.set(calendar.minute, 51); timeoff0.set(calendar.second, 00); //set timer rtc wakeup alarm manager object alarmmgr0.set(alarmmanager.rtc_wakeup, timeoff0.gettimeinmillis(), pi); pendingintent pi1 = pendingintent.getbroadcast(this, 0, i, pendingintent.flag_update_current); calendar timeoff1 = calendar.getinstance(); timeoff1.set(calendar.year, 2013); timeoff1.set(calendar.month, 6); timeoff1.set(calendar.day_of_month,1 ); timeoff1.set(calendar.hour_of_day, 8); timeoff1.set(calendar.minute, 54); timeoff1.set(calendar.second, 00); //set timer rtc wakeup alarm manager object alarmmgr0.set(alarmmanager.rtc_wakeup, timeoff1.gettimeinmillis(), pi1); }
this alarm receiver
public class oneshotalarm extends broadcastreceiver {
public void onreceive(context context, intent intent) {
toast.maketext(context, r.string.one_shot_received, toast.length_long).show(); mediaplayer mp =mediaplayer.create(context,r.raw.azan2); mp.start();
}
}
your broadcast receiver should not calling media player. alarms never know if phone going awake. broadcast receiver not wake phone long periods of time. wake fire go sleep. make correctly need broadcast receiver fire service. , service launch media player. here example program open source. includes wakelock make sure program not go sleep while alarm on. examine broadcast receivers , services. go together. luck happy coding.
to make run daily need launch alarm scheduling service broadcast receiver schedule next alarm. 1 alarm can go off @ time make program schedule next alarm launches way there 1 alarm on deck @ time.
Comments
Post a Comment