/** * Checks if the needed permissions are available * * @return If the permissions are available. If false is returned, the necessary prompts will be * shown */ private boolean checkWritePermissions() { @PermissionUtils.PermissionLevel int permissionLevel = PermissionUtils.getPermissionLevel(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); switch (permissionLevel) { case PermissionUtils.PERMISSION_AVAILABLE: LogUtil.v(TAG, "Permissions available"); return true; case PermissionUtils.PERMISSION_DENIED: new AlertDialog.Builder(getActivity(), app.getImgurTheme().getAlertDialogTheme()) .setTitle(R.string.permission_title) .setMessage(R.string.permission_rationale_upload) .setNegativeButton( R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { Snackbar.make(mMultiView, R.string.permission_denied, Snackbar.LENGTH_LONG) .show(); } }) .setPositiveButton( R.string.okay, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { ActivityCompat.requestPermissions( getActivity(), new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCodes.REQUEST_PERMISSION_WRITE); } }) .setOnCancelListener( new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { Snackbar.make(mMultiView, R.string.permission_denied, Snackbar.LENGTH_LONG) .show(); } }) .show(); break; case PermissionUtils.PERMISSION_NEVER_ASKED: default: LogUtil.v(TAG, "Prompting for permissions"); ActivityCompat.requestPermissions( getActivity(), new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, RequestCodes.REQUEST_PERMISSION_WRITE); break; } return false; }
private void onNeedsReadPermission(List<Uri> photoUris) { mMultiView.setViewState( mAdapter != null && !mAdapter.isEmpty() ? MultiStateView.VIEW_STATE_CONTENT : MultiStateView.VIEW_STATE_EMPTY); mPhotoUris = photoUris; int level = PermissionUtils.getPermissionLevel(this, Manifest.permission.READ_EXTERNAL_STORAGE); switch (level) { // Should never have gotten here if its available case PermissionUtils.PERMISSION_AVAILABLE: new DecodeImagesTask(this).doInBackground(mPhotoUris); break; case PermissionUtils.PERMISSION_DENIED: int uriSize = photoUris != null ? photoUris.size() : 0; new AlertDialog.Builder(getActivity(), theme.getAlertDialogTheme()) .setTitle(R.string.permission_title) .setMessage( getResources() .getQuantityString(R.plurals.permission_rational_file_access, uriSize, uriSize)) .setNegativeButton(R.string.cancel, null) .setPositiveButton( R.string.okay, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions( getActivity(), new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, RequestCodes.REQUEST_PERMISSION_READ); } }) .show(); break; case PermissionUtils.PERMISSION_NEVER_ASKED: ActivityCompat.requestPermissions( getActivity(), new String[] {Manifest.permission.READ_EXTERNAL_STORAGE}, RequestCodes.REQUEST_PERMISSION_READ); break; } }