Java – Security Exception: No persistable permission grants found for uri from ACTION_IMAGE_CAPTURE

Security Exception: No persistable permission grants found for uri from ACTION_IMAGE_CAPTURE… here is a solution to the problem.

Security Exception: No persistable permission grants found for uri from ACTION_IMAGE_CAPTURE

My app uses the camera to take pictures and use it for a long time.

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 get SecurityException: No persistable permission grants found

I read this
Getting Permission Denial Exception .
It works with ACTION_OPEN_DOCUMENT.
How do I get a perpetual license for my camera?

Solution

Access to the MediaStore URI is limited only to storage permissions (i.e. READ_EXTERNAL_STORAGE ) control, so you can access the URIS as long as you continue to hold storage permissions, so you don’t need to retain permissions at all in this case.

URI based permissions for ACTION_GET_ CONTENT, ACTION_OPEN_DOCUMENT, etc. By FLAG_GRANT_READ_URI_ PERMISSION gives a special one-time access to the URI included in the returned intent.

Only document URI(DocumentsContract.isDocumentUri() returns the truth value) allows you persistence permissions grant to URI More permanent access.

Related Problems and Solutions