Android - WakeLock - POST location on PUSH notification received when screen lock'd (parse.com) -


i want post location on pushreceived when screen lock'd. code works when screen on. wakelock not seem work...

when receiving push notification first time parse.com screen turns on , can see gps icon pops up. , database updates.

but second time push notfication onlocationcanged not triggered, , post never gets sendt. why ? screen turns on, , gps icon shown.

evrytime set debug @ point works:

locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, this); locationmanager.requestlocationupdates(locationmanager.network_provider, 0, 0, this); 

some sort of asynch tastk problem maby ?

here code:

public class pushnotificationreceiver extends parsepushbroadcastreceiver implements  locationlistener{          @override             public void onpushreceive(context context, intent intent) {                  //wakelock                 pm = (powermanager) context.getsystemservice(context.power_service);                 wakelock = pm.newwakelock((pm.screen_bright_wake_lock | pm.full_wake_lock | pm.acquire_causes_wakeup), "tag");                 wakelock.acquire();                  jsonobject pushdata;                 string alert = null;                 string title = null;                 try {                     pushdata = new jsonobject(intent.getstringextra(pushnotificationreceiver.key_push_data));                     alert = pushdata.getstring("alert");                     title = pushdata.getstring("title");                 } catch (jsonexception e) {}                  locationmanager locationmanager = (locationmanager) context.getsystemservice(context.location_service);                  //getting location                 getlocation(context, locationmanager);                  intent cintent = new intent(pushnotificationreceiver.action_push_open);                 cintent.putextras(intent.getextras());                 cintent.setpackage(context.getpackagename());                  pendingintent pcontentintent =                         pendingintent.getbroadcast(context, 0 /*just testing*/, cintent, pendingintent.flag_update_current);                  notificationcompat.builder builder = new notificationcompat.builder(context);                 builder                         .setsmallicon(r.drawable.car190)                         .setcontenttitle(alert)                         .setcontenttext(title)                         .setcontentintent(pcontentintent)                         .setautocancel(true);                   notificationmanager mynotificationmanager = (notificationmanager) context.getsystemservice(context.notification_service);                 mynotificationmanager.notify(1, builder.build());             }        private void getlocation(final context context, final locationmanager locationmanager){              locationmanager.requestlocationupdates(locationmanager.gps_provider, 0, 0, this);             locationmanager.requestlocationupdates(locationmanager.network_provider, 0, 0, this);              //stop receiving location after 5 sec             final handler handler = new handler();             handler.postdelayed(new runnable() {                 @override                 public void run() {                     locationmanager.removeupdates(pushnotificationreceiver.this);                      //wakelock release                     wakelock.release();                 }             }, 5000);            }  @override public void onlocationchanged(location location) {      currentlat = location.getlatitude() + "";     currentlng = location.getlongitude() + "";     currentdate = new date();     string username = tabfragment1.usernameresponse;      try {         jsonobject object = new jsonobject(username);         myusername = object.getstring("id");     } catch (jsonexception e) {         e.printstacktrace();     }      //post database     postlocation(mainactivity.getappcontext(), currentlat, currentlng, currentdate.tostring(), myusername); }   } 

remove this:

        //stop receiving location after 5 sec         final handler handler = new handler();         handler.postdelayed(new runnable() {             @override             public void run() {                 locationmanager.removeupdates(pushnotificationreceiver.this);                  //wakelock release                 wakelock.release();             }         }, 5000); 

and add

locationmanager.removeupdates(pushnotificationreceiver.this); wakelock.release(); 

in onlocationchanged, this:

@override public void onlocationchanged(location location) {      currentlat = location.getlatitude() + "";     currentlng = location.getlongitude() + "";     currentdate = new date();     username = tabfragment3.useremail;      postlocation(mainactivity.getappcontext(), currentlat, currentlng, currentdate.tostring(), username);     locationmanager.removeupdates(pushnotificationreceiver.this);     wakelock.release(); } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -