I'm trying to access to public Document directory by this method:
public static String getInternalRemovablePath() {
return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();
}
and then I create a directory inside it called GT-backup then save some files over there.
On the first try everything works fine. The directory GT-backup was created and I can access files inside it and edit them.
But whenever the user decides to clear app data or uninstall and install the app again => then when the app tries to access the same already existing directory that my app owns Gt-backup error says: open failed: EACCES (Permission denied).
If the user manually deletes the directory GT-backup inside the Documents directory, everything works again and the error disappears.
I think this case happening on Android 11 because the system decided that my app doesn't own the directory GT-backup even though my app created it before uninstalling it.
Any ideas to make Android know that this directory is created by the same app before uninstalling?
I tried to clear data and uninstall.. the same scenario happened, I'm assuming that if the app is re-installed the app, then I can access the same created directory by the same app.
That is not an option, sorry. Consider using the Storage Access Framework instead.