Skip to content

Instantly share code, notes, and snippets.

@gitzxon
Created August 19, 2016 03:30
Show Gist options
  • Save gitzxon/efa3a0ff627cf412ed793f8b037b5b40 to your computer and use it in GitHub Desktop.
Save gitzxon/efa3a0ff627cf412ed793f8b037b5b40 to your computer and use it in GitHub Desktop.
api23 android permission
/**
* 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;
}
@gitzxon
Copy link
Author

gitzxon commented Aug 19, 2016

copy from the demo of exoplayer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment