Lint False Positive for Missing Permission

Lint don’t see external functions for checking Android permissions. This code produce a Lint Missing Permission error: “Call requires permission which may be rejected by user…”

val FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION

if (isPermissionGranted(FINE_LOCATION)) {
    locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
    locationManager.getLastKnownLocation(...)
}

fun isPermissionGranted(permission: String) =  ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED

But if I checking directly, all is ok.

if (ContextCompat.checkSelfPermission(this, FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {

Android-specific lints are developed by Google, please report a bug to Report a bug  |  Android Developers

done

1 Like