Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - remove Security Exception warning

You are looking for (updated to improve clarity):

@Override
@SuppressWarnings({"MissingPermission"})
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (LOCATION_REQUEST_CODE == requestCode) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

            lastLocation = LocationServices.FusedLocationApi.getLastLocation(googleApiClient);


       }
}

EDITED:

The correct lint rule is MissingPermission, but there seems to be a bug that misplace it to some people.

So, please try @SuppressWarnings({"ResourceType"}), too.


If you are looking to ignore this lint warning, you can either do this inline:

//noinspection MissingPermission
Location lastLocation = FusedLocationApi.getLastLocation(locationClient);

or at method level:

@SuppressWarnings({"MissingPermission"})
public void toggleGPS(boolean enableGPS) {
  ...
}

you can use Android Studio Inspection To Generate @SuppressWarnings({"MissingPermission"}) For Your Method Or Class

android studio missing permission check