@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,
int[] grantResults) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
initializePlayer();
} else {
showToast(R.string.storage_permission_denied);
finish();
}
}
/**
- Checks whether it's necessary to request the {@link permission#READ_EXTERNAL_STORAGE}
- permission read the specified {@link Uri}s, requesting the permission if necessary.
- @param activity The host activity for checking and requesting the permission.
- @param uris {@link Uri}s that may require {@link permission#READ_EXTERNAL_STORAGE} to read.
- @return Whether a permission request was made.
*/
@TargetApi(23)
public static boolean maybeRequestReadExternalStoragePermission(Activity activity, Uri... uris) {
if (Util.SDK_INT < 23) {
return false;
}
for (Uri uri : uris) {
if (Util.isLocalFileUri(uri)) {
if (activity.checkSelfPermission(permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
activity.requestPermissions(new String[] {permission.READ_EXTERNAL_STORAGE}, 0);
return true;
}
break;
}
}
return false;
}
/**
- Like {@link android.os.Build.VERSION#SDK_INT}, but in a place where it can be conveniently
- overridden for local testing.
*/
public static final int SDK_INT =
(Build.VERSION.SDK_INT == 25 && Build.VERSION.CODENAME.charAt(0) == 'O') ? 26
: Build.VERSION.SDK_INT;
网友评论