Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SecurityException: No persistable permission grants found for uri from ACTION_IMAGE_CAPTURE

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?

like image 212
Mingwei Lin Avatar asked Mar 12 '23 15:03

Mingwei Lin


1 Answers

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.

like image 121
ianhanniballake Avatar answered Apr 24 '23 12:04

ianhanniballake