List of usage examples for android.content ContentResolver takePersistableUriPermission
public void takePersistableUriPermission(@NonNull Uri uri, @Intent.AccessUriMode int modeFlags)
From source file:com.frostwire.android.StoragePicker.java
public static String handle(Context context, int requestCode, int resultCode, Intent data) { String result = null;/*from w w w. j a va2s . c om*/ try { if (resultCode == Activity.RESULT_OK && requestCode == SELECT_FOLDER_REQUEST_CODE) { Uri treeUri = data.getData(); ContentResolver cr = context.getContentResolver(); final int takeFlags = data.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); cr.takePersistableUriPermission(treeUri, takeFlags); if (treeUri == null) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_null); result = null; } else { DocumentFile file = DocumentFile.fromTreeUri(context, treeUri); if (!file.isDirectory()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_not_directory); result = null; } else if (!file.canWrite()) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_cant_write); result = null; } else { LollipopFileSystem fs = (LollipopFileSystem) Platforms.fileSystem(); result = fs.getTreePath(treeUri); if (result != null && !result.endsWith("/FrostWire")) { DocumentFile f = file.findFile("FrostWire"); if (f == null) { file.createDirectory("FrostWire"); } } } } } } catch (Throwable e) { UIUtils.showShortMessage(context, R.string.storage_picker_treeuri_error); LOG.error("Error handling folder selection", e); result = null; } if (result != null) { ConfigurationManager.instance().setStoragePath(result); BTEngine.ctx.dataDir = Platforms.data(); BTEngine.ctx.torrentsDir = Platforms.torrents(); } return result; }
From source file:de.k3b.android.toGoZip.SettingsActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void grandPermission5(Context ctx, Uri data) { DocumentFile docPath = DocumentFile.fromTreeUri(ctx, data); if (docPath != null) { final ContentResolver resolver = ctx.getContentResolver(); resolver.takePersistableUriPermission(data, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); }/*w ww. j a va2 s . c o m*/ }
From source file:com.commonsware.android.diceware.PassphraseFragment.java
private static boolean obtainDurablePermission(ContentResolver resolver, Uri document) { boolean weHaveDurablePermission = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int perms = Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION; try {/* w w w . j ava 2 s .c o m*/ resolver.takePersistableUriPermission(document, perms); for (UriPermission perm : resolver.getPersistedUriPermissions()) { if (perm.getUri().equals(document)) { weHaveDurablePermission = true; } } } catch (SecurityException e) { // OK, we were not offered any persistable permissions } } return (weHaveDurablePermission); }
From source file:android.support.tests.GrantActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 12 && resultCode == RESULT_OK) { final ContentResolver resolver = getContentResolver(); resolver.takePersistableUriPermission(data.getData(), Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); }/*from w w w.j a v a 2 s . c o m*/ }
From source file:de.cachebox_test.splash.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override//from w w w . j a v a2 s . c o m protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == RESULT_OK && requestCode == Global.REQUEST_CODE_GET_WRITE_PERMISSION_ANDROID_5) { Uri treeUri = data.getData(); Intent intent = new Intent(Intent.ACTION_GET_CONTENT); final int takeFlags = intent.getFlags() & (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check for the freshest data. // Uri workPathUri = Uri.parse(workPath); ContentResolver cr = getContentResolver(); grantUriPermission(getPackageName(), treeUri, Intent.FLAG_GRANT_READ_URI_PERMISSION); cr.takePersistableUriPermission(treeUri, takeFlags); List<UriPermission> permissionlist = cr.getPersistedUriPermissions(); LolipopworkPath = "content://com.android.externalstorage.documents/tree/B8C5-760B%3A";// treeUri.getPath(); Thread th = new Thread(new Runnable() { @Override public void run() { Initial(width, height); } }); th.start(); } if (resultCode == RESULT_OK && requestCode == Global.REQUEST_CODE_PICK_FILE_OR_DIRECTORY_FROM_PLATFORM_CONECTOR) { if (resultCode == android.app.Activity.RESULT_OK && data != null) { // obtain the filename Uri fileUri = data.getData(); if (fileUri != null) { String filePath = fileUri.getPath(); if (filePath != null) { if (getFolderReturnListener != null) getFolderReturnListener.getFolderReturn(filePath); } } } return; } }