-1

I want to listen the state change of GPS dynamically, just like use broadcast. If I use mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER), that can't get state change infomation in real time. I think maybe use GpsStatus.Listener(), but dont't know how to achieve it at my fragment.

Kevin.Z
  • 135
  • 9
  • find more about [GpsStatus.Listener](http://stackoverflow.com/questions/18259039/gpsstatus-listener-works-only-if-gps-is-on) – Bharatesh Mar 20 '15 at 11:35

1 Answers1

0

You can listen to GPS changes by implementing LocationListener:

public class MyLocationListener implements LocationListener {

    //initialize locationManager

    public void init() {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
    }

    @Override
    public void onLocationChanged(Location location) {
    }

    @Override
    public void onStatusChanged(String s, int i, Bundle bundle) {
    }

    @Override
    public void onProviderEnabled(String s) {
    }

    @Override
    public void onProviderDisabled(String s) {
    }


}
Héctor
  • 24,444
  • 35
  • 132
  • 243