android - How to implement GPS Status change listener -
in android application sending location update server in each 5 minutes. using gms locationlistener. working fine. running inside service. wont work if user turned off gps. since running in service after turning on gps wait completing 5 minutes of update time. want when user turned on gps should trigger onlocationupdate listener.
for have did follows have initialized gpsstatus.listener in service, , implemented onstatuschange function. after changing gps status on off/ off on ,the function not triggering .
code
public class locationupdateservice extends service implements gpsstatus.listener, com.google.android.gms.location.locationlistener{ oncreate(bundle b){ super.oncreate(); registergpsstatuslistener(); } private void registergpsstatuslistener() { locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); locationmanager.addgpsstatuslistener(this); } @override public void ongpsstatuschanged(int event) { switch (event) { case gpsstatus.gps_event_started: log.e(tag, "ongpsstatuschanged started"); break; case gpsstatus.gps_event_stopped: log.e(tag, "ongpsstatuschanged stopped"); break; case gpsstatus.gps_event_first_fix: log.e(tag, "ongpsstatuschanged first fix"); break; case gpsstatus.gps_event_satellite_status: log.e(tag, "ongpsstatuschanged status"); break; } } @override public void onlocationchanged(location location) { //opertations } }
my queries ;
1- why method ongpsstatuschanged not calling after changing gps status.
2- how location inside onlocationchanged method, can call onlocationupdate method.
note: please not recommend use broadcastreceiver since requires huge code modification of current code
i think trying know when user switches gps on or off device. in case can have @ this answer.this correct , reliable way detect gps on/off switch (at least 1 worked me).
Comments
Post a Comment