0

I know there are others similar thread, but I believe that a case was not evaluated: When you create a file and then unistall and reinstall the app.

My app saves pdf in the shared 'Documents' folder, getting the path through Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) So my pdf is saved in Documents -> MyAppName

If I unistall and then install the app, I can't see all the pdf files created before (I think the new installation is seen like a different application, could be?). I can see the photos, because we have the Manifest.permission.READ_MEDIA_IMAGES but what about documents? Am I forced to implement SAF and let the user browse and choose the folder (with the possibility that he will choose the wrong folder)? In this case, how can I check that I have permissions for that specific folder?

akLab
  • 13
  • 4
  • 1
    Just use SAF with ACTION_OPEN_DOCUMENT to let the user choose the file. You get permission for the choosen file. Not for the folder. – blackapps Jun 28 '23 at 14:44
  • 1
    You can also use ACTION_OPEN_DOCUMENT_TREE to let the user choose your folder. You will know that it is your folder as the name of it will be in the obtained uri. You get temporarily permissions for the chosen folder and all the files in it but you can make them persistable. If you make the uri persistent it will also for ever be in the list of persistable uri permissions for your app. – blackapps Jun 28 '23 at 14:46
  • thank you! so I can check that the user has chosen the correct folder, but how do I check that I still have permissions on that specific folder? Could they be reset by android like manifest permissions? – akLab Jul 03 '23 at 07:14
  • You can request the list of persistable uri permissions for your app and look if that uri is contained. Or just use the uri as it will throw if not valid. Android will never reset a persistable uri permission. – blackapps Jul 03 '23 at 08:35

0 Answers0