Shirish Herwade Shirish Herwade - 4 months ago 25
Android Question

how to remove "call requires permission which may.." error in Android Studio

My code

private void continueCall() {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNoToCall));
startActivity(callIntent);
}


Above requires whether user grant permission
CALL_PHONE
at run time which I have checked as

private void call() {
if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED) {
continueCall();
} else {
requestCallPermission();
}
}


Still Android studio showing error "call requires permission which may..."

How to remove this error? Or at least suppress it.

Answer

The method continueCall() could be called from multiple places. So it isn't guaranteed to have the permission check in call()

So you can only suppress the error by adding:

@SuppressWarnings("MissingPermission")