Event For Gps On/off State Change
I want to listen a GPS state changes in my app, is there in android any intent-action which I can use in a broadCast receiver like an android.net.conn.CONNECTIVITY_CHANGE for netwo
Solution 1:
You can register a BroadcastReceiver for listening to Intent Action PROVIDERS_CHANGED_ACTION
.
or you can try this snippet
GpsStatus.Listener gpsListener = new GpsStatus.Listener() {
publicvoidonGpsStatusChanged(intevent) {
if( event == GpsStatus.GPS_EVENT_FIRST_FIX){
showMessageDialog("GPS fixed");
}
}
};
OR
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.addGpsStatusListener(new android.location.GpsStatus.Listener()
{
publicvoidonGpsStatusChanged(intevent)
{
switch(event)
{
case GPS_EVENT_STARTED:
// do your tasksbreak;
case GPS_EVENT_STOPPED:
// do your tasksbreak;
}
}
});
Post a Comment for "Event For Gps On/off State Change"