android - Alarm manager and broadcaster receiver not working -
my alarm manager class
public class psmscheduler {
public static void setschedule(context context) { setschedule(context,0,0,5); setschedule(context, 18, 30, 0); } private static void setschedule(context context, int hour, int min, int sec) { // request code distinguish different stress meter schedule instances int requestcode = hour * 10000 + min * 100 + sec; intent intent = new intent(context, emaalarmreceiver.class); pendingintent pi = pendingintent.getbroadcast(context, requestcode, intent, pendingintent.flag_cancel_current); //set pending intent call emaalarmreceiver. calendar calendar = calendar.getinstance(); calendar.settimeinmillis(system.currenttimemillis()); calendar.set(calendar.hour_of_day, hour); calendar.set(calendar.minute, min); calendar.set(calendar.second, sec); if(calendar.gettimeinmillis() < system.currenttimemillis()) { calendar.add(calendar.date, 1); } //set repeating alarm, , pass pending intent, //so broadcast sent everytime alarm // triggered alarmmanager alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); alarmmanager.setrepeating(alarmmanager.rtc_wakeup, calendar.gettimeinmillis(), alarmmanager.interval_day, pi); } }
my broadcast receiver
public class emaalarmreceiver extends broadcastreceiver { @override public void onreceive(final context context, intent intent) { startpsm(context); } private void startpsm(context context) { intent emaintent = new intent(context, mainactivity.class); emaintent.setflags(intent.flag_activity_new_task); context.startactivity(emaintent); } }
my main activity
public psmscheduler scheduler = new psmscheduler(); public emaalarmreceiver receiver = new emaalarmreceiver(); ringtone r; vibrator v; @override protected void oncreate(final bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); scheduler.setschedule(this);
i'm not sure why isn't working. have receiver declared in manifest. thoughts or suggestions appreciated.
Comments
Post a Comment