List of usage examples for android.content UriPermission isWritePermission
public boolean isWritePermission()
From source file:com.veniosg.dir.mvvm.model.storage.access.SafStorageAccessManager.java
private boolean permissionGrantedForParentOf(@NonNull File fileInStorage) { List<UriPermission> permissions = context.getContentResolver().getPersistedUriPermissions(); for (UriPermission permission : permissions) { String storageRoot = getExternalStorageRoot(fileInStorage, context); DocumentFile grantedDocFile = fromTreeUri(context, permission.getUri()); boolean grantedOnAncestor = areSameFile(storageRoot, grantedDocFile); if (permission.isWritePermission() && grantedOnAncestor) return true; }//from ww w.j a v a2 s .c o m return false; }
From source file:com.almalence.opencam.SavingService.java
@TargetApi(19) public static DocumentFile getSaveDirNew(boolean forceSaveToInternalMemory) { DocumentFile saveDir = null;/*w w w .j ava 2 s.com*/ boolean usePhoneMem = true; String abcDir = "Camera"; if (sortByData) { Calendar rightNow = Calendar.getInstance(); abcDir = String.format("%tF", rightNow); } int saveToValue = Integer.parseInt(saveToPreference); if (saveToValue == 1 || saveToValue == 2) { boolean canWrite = false; String uri = saveToPath; try { saveDir = DocumentFile.fromTreeUri(ApplicationScreen.instance, Uri.parse(uri)); } catch (Exception e) { saveDir = null; } List<UriPermission> perms = ApplicationScreen.instance.getContentResolver() .getPersistedUriPermissions(); for (UriPermission p : perms) { if (p.getUri().toString().equals(uri.toString()) && p.isWritePermission()) { canWrite = true; break; } } if (saveDir != null && canWrite && saveDir.exists()) { if (sortByData) { DocumentFile dateFolder = saveDir.findFile(abcDir); if (dateFolder == null) { dateFolder = saveDir.createDirectory(abcDir); } saveDir = dateFolder; } usePhoneMem = false; } } if (usePhoneMem || forceSaveToInternalMemory) // phone memory (internal // sd card) { saveDir = DocumentFile .fromFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)); DocumentFile abcFolder = saveDir.findFile(abcDir); if (abcFolder == null || !abcFolder.exists()) { abcFolder = saveDir.createDirectory(abcDir); } saveDir = abcFolder; } return saveDir; }
From source file:com.xperia64.timidityae.TimidityActivity.java
@SuppressLint("NewApi") public void initCallback() { if (Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { List<UriPermission> permissions = getContentResolver().getPersistedUriPermissions(); int trueExt = 0; for (File f : getExternalFilesDirs(null)) { if (f != null) trueExt++;/* w ww . j a v a 2 s . c om*/ } if ((permissions == null || permissions.isEmpty()) && Globals.shouldLolNag && trueExt > 1) { new AlertDialog.Builder(this).setTitle("SD Card Access").setCancelable(false).setMessage( "Would you like to give Timidity AE write access to your external sd card? This is recommended if you're converting files or would like to place Timidity AE's data directory there. Problems may occur if a directory other than the root of your SD card is selected.") .setPositiveButton("Yes", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); startActivityForResult(intent, 42); } }).setNegativeButton("No, do not ask again", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Globals.prefs.edit().putBoolean("shouldLolNag", Globals.shouldLolNag = false) .commit(); initCallback2(); } }).setNeutralButton("No", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { initCallback2(); } }).show(); } else { for (UriPermission permission : permissions) { if (permission.isReadPermission() && permission.isWritePermission()) { Globals.theFold = permission.getUri(); } } initCallback2(); } } else { initCallback2(); } }