Alexander
Alexander

Reputation: 431

Android Q - User remove in app settings persistent permission on uri. How to request permisson again?

Android Q. I create file in android using Storage Access Framework(https://developer.android.com/guide/topics/providers/document-provider) For example some image or video in Downloads directory. I use ACTION_CREATE_DOCUMENT for this and after it I get persistent permission for this uri. As a result I get access for this file from my app after updating my application, restarting device. But user can go to system app settings and remove this permission. And after it I don't have access to this file by this Uri(for example I stored this Uri in database). But I need to show this image/video for user. How should I do it? How can I request permission for this Uri again? ACTION_OPEN_DOCUMENT doesn't support opening only one certain Uri?

Upvotes: 1

Views: 620

Answers (1)

Tuan Nguyen
Tuan Nguyen

Reputation: 140

According to the Scoped Storage document:

An app that has a filtered view always has read/write access to the files that it creates, both inside and outside its app-specific directory. Your app doesn't need to declare any storage permissions to access these files.

But we have a problem in Android Q that we cannot access a file by using raw path (create a File() instance with raw path or raw Uri), so we must access the file via contentResolver.

For your case, if you already created and saved the file Uri to your database, just use context.contentResolver.openOutputStream(your-uri) or context.contentResolver.openInputStream(your-uri)to access your file.

Upvotes: 2

Related Questions