Reputation: 23
I'm pretty new in Android programming. I want to open a directory an get persistent read access on it. I add the flag FLAG_GRANT_PERSISTABLE_URI_PERMISSION
to the intent.
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
startActivityForResult(Intent.createChooser(intent, null), MY_REQUEST);
On the onActivityResult
Methode, I fetch the data
to get the uri
like
Uri uri = data.getData()
cUri = DocumentsContract.buildChildDocumentsUriUsingTree(uri,
DocumentsContract.getTreeDocumentId(uri));
getContentResolver().takePersistableUriPermission(cUri,Intent.FLAG_GRANT_READ_URI_PERMISSION);
I got an SecurityException: No persistable permission grants found
But the permissions are set as intent.flag.
Why I got this error and how can I avoid it?
Thanks Peter
Upvotes: 1
Views: 419
Reputation: 1007399
I add the flag FLAG_GRANT_PERSISTABLE_URI_PERMISSION to the intent
That is not what that flag is for.
On the onActivityResultMethode, I fetch the data to get the uri like
Delete cUri
. Use uri
with takePersistableUriPermission()
.
Upvotes: 2