Linter Errors on Location Services


#1

I was getting error warnings from the Android Studio linter, and I had to add the if statement here to make that error go away.

private void findImage() {
LocationRequest request = LocationRequest.create();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
request.setNumUpdates(1);
request.setInterval(0);

if ( Build.VERSION.SDK_INT >= 23 &&
    ContextCompat.checkSelfPermission( getContext(), 
    android.Manifest.permission.ACCESS_FINE_LOCATION ) != 
        PackageManager.PERMISSION_GRANTED &&
    ContextCompat.checkSelfPermission( getContext(), 
        android.Manifest.permission.ACCESS_COARSE_LOCATION) != 
    PackageManager.PERMISSION_GRANTED) {
        return  ;
}

LocationServices.FusedLocationApi
    .requestLocationUpdates(mClient, request, new LocationListener() {
      @Override
      public void onLocationChanged(Location location) {
        Log.i(TAG, "Got a fix: " + location);
      }
    });

}

I also did what Tom suggested here to request the permissions.