My app use camera to take a photo and use it for long term.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri resultUri = null;
resultUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new ContentValues());
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, resultUri);
startActivityForResult(imageCaptureIntent, IMAGE_CAPTURE_REQUEST_CODE);
But when I call takePersistableUriPermission(), I will get SecurityException: No persistable permission grants found
I've read this Getting Permission Denial Exception. It works perfect to ACTION_OPEN_DOCUMENT. How do I get a persistent permission from Camera?
Access to MediaStore
URIs are only controlled by the storage permissions (i.e., READ_EXTERNAL_STORAGE) so as long as you continue to hold the storage permission, you can access the Uris so in this case you don't need to persist permissions at all.
URI based permissions, used in ACTION_GET_CONTENT
, ACTION_OPEN_DOCUMENT
, etc. give special one time access to a URI via the FLAG_GRANT_READ_URI_PERMISSION being included with the returned Intent
.
It is only document URIs (ones where DocumentsContract.isDocumentUri() returns true) that allow you to persist permissions to give more permanent access to a Uri.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With