0

I want to gain persistent read access to files received via onNewIntent():

public void onNewIntent(Intent intent) {
    Uri uri = getIntent().getData();
    getContentResolver().takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION); // fails
}

But this fails because takePersistableUriPermission is intended to be used with ACTION_OPEN_DOCUMENT (from the Storage Access Framework):

System.err: java.lang.SecurityException: No persistable permission grants found for UID 10222 and Uri content://...

Is there a way to get persistent read permission for files received via onNewIntent()? Or do I have to copy the file to the local app directory?

Regards,

Hyndrix
  • 4,282
  • 7
  • 41
  • 82
  • If you receive something via onNewIntent() there should be someting that has sent you that intent. Please start with explaining how exaxtly that happened. And what is the value of uri.toString()? – blackapps Oct 26 '19 at 08:29
  • 1
    You can investigate getIntent().getFlags() to see if they contain the read or write flag. If not then you can do nothing. You should always OR the received flags with the wanted flags. – blackapps Oct 26 '19 at 08:31
  • 1
    "Is there a way to get persistent read permission for files received via onNewIntent()?" -- AFAIK, not generally. In theory, if the `Uri` was from SAF itself, you might be able to use `takePersistableUriPermission()`, but there is no guarantee that the `Uri` will be from SAF. It could be from a `FileProvider` or anything else. "Or do I have to copy the file to the local app directory?" -- that would be the safest option. – CommonsWare Oct 26 '19 at 10:58

0 Answers0