java - AlarmManager fires alarm in the wrong time if timezone is different than GMT(UTC) -
i know question asked billion times, , have tried make use of answers can't seem work expect to. i'm having trouble setting alarms via alarmmanager - seems working fine utc ( or gmt -whatever prefer), when comes other timezones alarms not fired @ right time. if set alarm @ 12:00 if timezone (+2) fires @ 14:00, 2 hrs late.
here's snippet:
//todays date in seconds long current = (system.currenttimemillis()/86400000)*86400; long time =current + 43200; alarmmanager.set(alarmmanager.rtc_wakeup, time*1000, operationbroadcast);
the time on device 6:42 here's i've found in alarmmanagers "dump" file
rtc_wakeup #10: alarm{420f49b8 type 0 com.pocketenergy.androidbeta} type=0 when=+7h17m37s418ms repeatinterval=0 count=0 operation=pendingintent{420f3b20: pendingintentrecord{420f4808 com.pocketenergy.androidbeta broadcastintent}}
as far i've read on several places time should set in utc whatever timezone selected on actual device, have tried lot of different stuff calendar, example:
//todays date in seconds long current = (system.currenttimemillis()/86400000)*86400; long time =current + 43200; calendar calendar = calendar.getinstance(); calendar.settimeinmillis(time*1000); timezone timezone= timezone.gettimezone("utc"); //also tried timezone.getdefault(); calendar.settimezone(timezone); time = cal.gettimeinmillis(); alarmmanager.set(alarmmanager.rtc_wakeup, time, operationbroadcast);
same outcome. ideas, anybody? :)
so, got work. here's code :)
calendar calendar = calendar.getinstance(); calendar.settimeinmillis(system.currenttimemillis()); calendar.set(calendar.hour_of_day, 12); calendar.set(calendar.minute, 0); calendar.set(calendar.second, 0); alarmmanager.set(alarmmanager.rtc_wakeup, time, operationbroadcast);
Comments
Post a Comment