0

I want to create a custom method that will check for Android permissions at runtime.

The problem is that when I use this method instead of the one proposed by the Android Studio, I get a lint warning saying I should check for permissions.

How can I tell lint that my method does the same work as the method from the Android studio? I don't want to be forced to use @SuppressLint("MissingPermission") every time I use my method. Here is an example of what I'm trying to achieve :

if (PermissionManager.isPermissionGranted(this, /* A PERMISSION*/)
{ 
    //Permission Granted 
}

Is there any way to tell lint that isPermissionGranted will check if the permission has been granted?

Quantum_VC
  • 185
  • 13
liltof
  • 2,153
  • 2
  • 14
  • 23
  • Check [this answer](https://stackoverflow.com/a/36193309/5752443). It's presenting a trick! – YUSMLE Mar 06 '22 at 16:08

1 Answers1

0

This is the method to check to write external storage.

public boolean checkPermission() {
    int result = ContextCompat.checkSelfPermission(mContext, android.Manifest.permission.WRITE_EXTERNAL_STORAGE);
    if (result == PackageManager.PERMISSION_GRANTED) {
        return true;
    } else {
        return false;
    }
}

This is the dynamic method to check any kind of permission granted or not.

public boolean checkPermission(String permission) {
    int result = ContextCompat.checkSelfPermission(mContext,permission);
    if (result == PackageManager.PERMISSION_GRANTED) {
        return true;
    } else {
        return false;
    }
}
Mayur Sojitra
  • 690
  • 7
  • 19
  • 2
    Okay! I just realized that my method was correct, but the fact is that you HAVE to name the function checkPermission. This is the way lint detects if you checked the permission. Can you edit your answer to explain that so I will accept it as the correct answer? because your answer helped me to realize that but you don't explicitly say it – liltof Oct 05 '18 at 16:09