How Can I Know If My App's Camera Permission Is Granted?
Solution 1:
I want to know if my app's camera permission is granted or not
If your targetSdkVersion
is 23 or higher, and you are running on an Android 6.0+ device, use checkSelfPermission()
. The native implementation of checkSelfPermission()
is on Context
; ContextCompat
has a version that will not crash on older Android devices.
If your targetSdkVersion
is 22 or lower, or you are running on an Android 5.1 or older device, you always have your requested permissions (exception: possibly some custom ROMs).
If your targetSdkVersion
is 22 or lower, and you are running on an Android 6.0 or higher device, you also always have your requested permissions, in terms of the methods that you are calling as outlined in your question. The user, in Settings, can block your access to data associated with those permissions, but technically the user is not actually revoking the permissions themselves (though we often say they are just to keep the explanation simple). I know of no way for you to determine that the user is blocking your camera access, other than by catching the relevant exceptions when you attempt to access the camera. Note that those exceptions will be raised in other scenarios (e.g., camera access is blocked by device policy).
Post a Comment for "How Can I Know If My App's Camera Permission Is Granted?"