Basically, I'm trying to let users choose pictures from their phone's image gallery to use as background images in my app.
I'm considering using takePersistableUriPermission. I'm wondering how this works with files that are cached locally, but exist on a remote server.
For example, the Google Photos app permanently stores photos in the cloud but some of those photos are available locally on the device (cached). If a user selects a recent photo, I gain access to it via takePersistableUriPermission, great! Time goes by and that photo is not so recent anymore and Google Photos removes it locally. Do I still have access to it?
Update:
I just learned that the number of persistable uri's your app can have is limited.
For a long time, it was 128. Android 11 raised it to 512, and it seems to be 512 for Android 12 as well.
You can and should release uri permissions you no longer need like so:
final int releaseFlags = intent.getFlags()
& (Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
getContentResolver().releasePersistableUriPermission(fileUri, releaseFlags);
Update 2:
It's also possible for the app that owns the uri to revoke permission for that uri via revokeUriPermission.