简体   繁体   中英

Android: onRequestPermissionsResult lint warning

I have a check in my app for whether a user has a certain permission, and if they don't have that permission then I request it:

if (ActivityCompat.checkSelfPermission(someactivity, Manifest.permission_group.LOCATION) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(someactivity, PERMISSIONS_LOCATION, REQUEST_LOCATION);

            } else {
                useThePermission();
            }

so far so good. I then implement OnRequestPermissionsResultCallback for the activity and override the onRequestPermissionsResult like so:

@Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (Util.verifyPermissions(grantResults)) {
            useThePermission();
        }
    }

and this is where things get messy - because by adding the first check I lose the lint warning about the user perhaps not having the correct permission, however, I get the exact same warning for useThePermission() inside onRequestPermissionsResult(). Is there anything I can do about this other than just suppressing the lint check for that method?

Naming the method checkPermission() seems to workaround this issue. Not sure if that's gonna stay like that but this seems to be the only way at the moment as the annotation used internally is hidden.

Using the "onRequestPermissionsResult" function doesn't mean you need to use OnRequestPermissionsResultCallback , because the activity already handles it for you.

It works without having the "OnRequestPermissionsResultCallback" text. Just add "onRequestPermissionsResult" to the activity, and that's it. It will get called.

However, I have no idea when "OnRequestPermissionsResultCallback" is called.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM