Rinaldi Segecin
Rinaldi Segecin

Reputation: 517

What's the workaround or maybe deprecated version of 'checkSelfPermission'?

I'm trying to run the Android sample camera2basic. There's a method calling checkSelfPermission that requires API level 23 but I'm running on my phone that only supports API level 21. What's the workaround or maybe deprecated version of checkSelfPermission?

PS: It's checking the permission for the camera.

if (getActivity().checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    requestCameraPermission();
    return;
}

Upvotes: 3

Views: 7093

Answers (2)

unbekant
unbekant

Reputation: 1555

As noted in Google's documentation:

Revision 23 of the v4 and v13 support libraries provide several new methods for managing permissions. The support library methods work properly on any device that can use those libraries. Thus, if you use the support library methods, you do not need to check whether your app is running on a device with the M Developer Preview. If an app is installed on a device running the M Preview, the support library methods behave the same as their framework equivalents. If the device is running an earlier version of Android, the methods behave appropriately, as described below.

So, for what you are trying to do you should use:

ContextCompat.checkSelfPermission()

Everything you need should be available in Support library methods for handling permissions

EDIT 12/02/2015: Google moved the link above. Same information is now available here: Check for Permissions

Upvotes: 2

Kane O'Riley
Kane O'Riley

Reputation: 2528

Make sure you're using v23 of the support library, then you can use ContextCompat.checkSelfPermission, which is a static method backwards compatible with older Android versions.

More info: ContextCompat

Upvotes: 6

Related Questions