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
Post a Comment