android - Alarm manager Not triggering with correct time -
i know common thread in didn't find answer question . want trigger dynamic broadcast receiver @ particular time. using below code
public void method1() { br = new broadcastreceiver() { @override public void onreceive(context c, intent i) { dotask(); } }; registerreceiver(br, new intentfilter("com.xxxx.wakeup")); pi = pendingintent.getbroadcast(this, 0, new intent("com.xxxx.wakeup"), 0); = (alarmmanager) (this.getsystemservice(context.alarm_service)); setalarmmanagerobject(); }
and setalarmmanagerobject() method here
public void setalarmmanagerobject() { calendar cal = calendar.getinstance(); int year = cal.get(calendar.year); int month = cal.get(calendar.month); int day = cal.get(calendar.day_of_month); cal.set(year, month, day , com.xxxx.constants.alarmhour , com.xxxx.constants.alarmminute , com.xxxx.alarmsecond); am.setrepeating(alarmmanager.elapsed_realtime, cal.gettimeinmillis(), alarmmanager.interval_day, pi); }
my problem when used alarmmanager.rtc_wakeup wake when device off. don't want property in app. used alarmmanager.elapsed_realtime, elapsed_realtime alarm manager not triggering. want alarm manager trigger exact @ same time. if device off or sleep condition alarm manager off after device wake up.it should trigger @ exact time. appreciated.
you need use this:-
alarmmanager.set(alarmmanager.elapsed_realtime_wakeup (or alarmmanager.elapsed_realtime), systemclock.elapsedrealtime() + constants.delay_in_millis, pendingintent);
you can calculate delay_in_millis time delay in milliseconds current system time.
for repeating alarm can have code this:-
alarmmanager.setrepeating(alarmmanager.elapsed_realtime_wakeup, systemclock.elapsedrealtime() + constants.delay_in_millis, constants.one_day_in_millis, pendingintent);
Comments
Post a Comment