tomazj
tomazj

Reputation: 313

Android 11: regain app folder ownership after uninstall

I have a question regarding storage changes in Android 11. If I understand correctly, app can read/write/delete the files it created. Also I can then access those files for example like this:

File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/ExampleApp/" + fileName);

ExampleApp is the app folder I created in the public Downloads folder. But once the app gets uninstalled, it losses the ownership over all the files it created. Is there a way to regain the ownership of the ExampleApp folder by the app once it gets reinstalled? One could use scoped storage & ACTION_OPEN_DOCUMENT_TREE, but that would then have to be done on every fresh start of application, no? Files in the app folder are in multiple sub-folders and of non media format, so I can't utilize Media Store API.

Permissions used:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Scoped storage permissions:
https://developer.android.com/training/data-storage#scoped-storage

Upvotes: 6

Views: 1104

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007474

Is there a way to regain the ownership of the ExampleApp folder by the app once it gets reinstalled?

No.

One could use scoped storage & ACTION_OPEN_DOCUMENT_TREE, but that would then have to be done on every fresh start of application, no?

No. Programmers can use takePersistableUriPermission() on ContentResolver to get durable access to user-selected tree.

Upvotes: 2

Related Questions