android - Alarm manager not pushing data in server periodically for nougat -
i using alarmmanager call pendingintent. triggers wakefulbroadcastreceiver push data in server periodically. nougat, not pushing in periodic time. , draining battery much.
my code here-> public static void startsyncalarm(string enteredtime) { // construct intent execute alarmreceiver intent intent = new intent(context, syncdbtoserveralarmreceiver.class); intent.putextra(constants.entered_time, enteredtime); // create pendingintent triggered when alarm goes off final pendingintent pintent = pendingintent.getbroadcast(context, syncdbtoserveralarmreceiver.request_code, intent, pendingintent.flag_update_current); // alarm needs set after 5 minutes of entered time // convert entered time milliseconds // create date object using string time format using simple date format simpledateformat format = new simpledateformat("mm/dd/yyyy hh:mm:ss aa"); try { date entereddate = format.parse(enteredtime); long enteredtimeinmillis = entereddate.gettime(); long intervalmillis = 30 * 60 * 1000; // 30 minutes gap long triggeratmillis = enteredtimeinmillis + intervalmillis; log.d(tag, "start alarm, enteredtimemillis = " + enteredtimeinmillis + "\ntriggeratmillis = " + triggeratmillis); //long firstmillis = system.currenttimemillis(); // alarm set right away syncdbalarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); // setup periodic alarm every 5 minutes syncdbalarmmanager.setrepeating(alarmmanager.rtc_wakeup, triggeratmillis/*firstmillis*/, intervalmillis, pintent); } catch (parseexception e) { e.printstacktrace(); } }
Comments
Post a Comment