Created
August 19, 2016 03:30
-
-
Save gitzxon/efa3a0ff627cf412ed793f8b037b5b40 to your computer and use it in GitHub Desktop.
api23 android permission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Checks whether it is necessary to ask for permission to read storage. If necessary, it also | |
* requests permission. | |
* | |
* @return true if a permission request is made. False if it is not necessary. | |
*/ | |
@TargetApi(23) | |
private boolean maybeRequestPermission() { | |
if (requiresPermission(contentUri)) { | |
requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0); | |
return true; | |
} else { | |
return false; | |
} | |
} | |
@TargetApi(23) | |
private boolean requiresPermission(Uri uri) { | |
return Util.SDK_INT >= 23 | |
&& Util.isLocalFileUri(uri) | |
&& checkSelfPermission(permission.READ_EXTERNAL_STORAGE) | |
!= PackageManager.PERMISSION_GRANTED; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy from the demo of exoplayer