android - How to check if GPS is connected and the position updated -


the gps needs connected gps satellite track position in realtime. problem lose connection , if invoke

    locationmanager.getlastknownlocation(provider); 

i last known location may differ actual position. how check if gps connected , position updated before invoke / use getlastknownlocation?

implement gpsstatus.listener interface on activity or service:

public class locationactivity extends activity implements gpsstatus.listener {     private locationmanager locationmanager;     @override    public void oncreate(bundle savdedinstancestate)        ....        ....        locationmanager = (locationmanager)getsystemservice(location_service);        locationmanager.addgpsstatuslistener(this);    }     @override    public void ongpsstatuschanged(int event)     {        switch (event)        {         case gpsstatus.gps_event_satellite_status:         break;         case gpsstatus.gps_event_first_fix:           /* when gps activated; add code here how want application react. */                                 break;         case gpsstatus.gps_event_started:         break;         case gpsstatus.gps_event_stopped:         break;       }    } } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -