2021年2月5日星期五

On Android 7.1 (API 25) LocationManager crashes with Fatal Exception in android.location.LocationListener.onStatusChanged

When I run my app location enabled app in an Android 6.0 device or Android 10 everything works fine, but when I run it in an Android 7.1 device it crashes right after the user gives location permission with the following message:

Process: com.hkc.incidencias, PID: 6853  java.lang.AbstractMethodError: abstract method "void android.location.LocationListener.onStatusChanged(java.lang.String, int, android.os.Bundle)"      at android.location.LocationManager$ListenerTransport._handleMessage(LocationManager.java:304)      at android.location.LocationManager$ListenerTransport.-wrap0(LocationManager.java)      at android.location.LocationManager$ListenerTransport$1.handleMessage(LocationManager.java:242)      at android.os.Handler.dispatchMessage(Handler.java:102)      at android.os.Looper.loop(Looper.java:154)      at android.app.ActivityThread.main(ActivityThread.java:6119)      at java.lang.reflect.Method.invoke(Native Method)      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)  

My Fragment implements LocationListener and it takes care of checking the user permissions previous to requesting location updates.

private void startLocationUpdates() {      if (ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&              ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {          return;      }        LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);        // Start updating the user location with a minimum update time and distance set so it doesn't affect too much the battery life.      // Every time the position of the user changes, the onLocationChanged function will be called      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 10, this);  }  

And then it overrides onLocationChanged:

// The position of the user has changed  @Override  public void onLocationChanged(@NonNull Location location) {      // Store the user position      myPosition = new LatLng(location.getLatitude(), location.getLongitude());           ...  }  
https://stackoverflow.com/questions/66072587/on-android-7-1-api-25-locationmanager-crashes-with-fatal-exception-in-android February 06, 2021 at 09:04AM

没有评论:

发表评论