android - onGpsStatusChanged NOT firing for GpsStatus.Listener -


would listen gps availability. followed this. however, ongpsstatuschanged not fired when disabled/enabled gps. tried on multiple phones. also, looked related stackoverflow qns such this, this , this. met no success. appreciated. thanks!

code snippets:

listener

listener mgpslistener = new gpsstatus.listener() {      @override     public void ongpsstatuschanged(final int event) {         log.d(tag, "---ongpsstatuschanged---");         switch (event) {             case gpsstatus.gps_event_started:                 log.d(tag, "gps_event_started");                 break;             case gpsstatus.gps_event_first_fix:                 log.d(tag, "gps_event_first_fix");                 break;             case gpsstatus.gps_event_stopped:                 log.d(tag, "gps_event_stopped");                 break;             case gpsstatus.gps_event_satellite_status:                 log.d(tag, "gps_event_satellite_status");                 break;             default:                 log.d(tag, "something_else");                 break;         }       }   }; 

service

.....     @override     public int onstartcommand(intent intent, int flags, int startid) {         super.onstartcommand(intent, flags, startid);         log.d(tag, "onstartcommand");         context ctx = getbasecontext();         log.d(tag, "done, " + ctx);         locationmanager locmanager = (locationmanager)         ctx.getsystemservice(context.location_service);         log.d(tag, "got locmanager");         locmanager.addgpsstatuslistener(mgpslistener);         log.d(tag, "added -> locmanager.addgpsstatuslistener(mgpslistener)");         return start_sticky;       } ..... 

could see log statements context, locationmanager, etc. nothing ongpsstatuschanged @ all.

edit1 manifest contains following permissions:

<uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_coarse_location"/> <uses-permission android:name="android.permission.access_fine_location"/> 

ok, here finding.

if want ongpsstatuschanged of gpsstatus.listener called need not register locationmanager using addgpsstatuslistener listen location updates requestlocationupdates.

as started listening location updates means of requestlocationupdates of locationmanager class, started getting gps status changes.


Comments

Post a Comment

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -