1

I receive crush, when user turn off the gps. I have code like this to detect location`s user

if(locationManager == null) {
        locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }
    if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000L,
                15f, mLocationListener);
    } else if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000L,
                15f, mLocationListener);
    } else {
        Toast.makeText(this, "Please turn on gps on ypur phone", Toast.LENGTH_SHORT).show();
    }

When user open app with gps, then turn off it, I receive crush like this

java.lang.AbstractMethodError: abstract method "void android.location.LocationListener.onProviderDisabled(java.lang.String)"

I tried to detect when user turn off gps, but I get crush earlier, then receiver detect

1

1 Answer 1

0

Find the declaration of mLocationListerner. Surely it overrite onLocationChanged(). But you may have forgotten override onProviderDisabled(). Do it even if it's empty. Override also onStatusChanged() and onProviderEnabled().

Luck.

LocationListener mLocationListener = new LocationListener() {
   @Override
   public void onLocationChanged(Location location) {
      ....
   }

   @Override
   public void onProviderDisabled(String provider) { }

   @Override
   public void onStatusChanged(String provider, int status, Bundle extras) {}

   @Override
   public void onProviderEnabled(String provider) { }

};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.