EACCES (Permission denied) also on files created by my app?

Viewed 340

Premise
Soon I will have to update my app from android 10 to android 11.
compileSdkVersion 30
targetSdkVersion 30

I already had in the previous version
android: requestLegacyExternalStorage = "true" (Documentation says this will be ignored on android 11)
I already had in the previous version the FileProvider definition and so I left it as is.
Everything works perfectly on ANDROID 10.

Now, From the tests carried out on the emulator (Android 11) my app is still able to create the "my custom directory" in "download / myappname" without problems even though I have the target at SDK 30... but hadn't this been prevented?

And since it allows me to do this, why then does EACCES (Permission denied) give me an error if I try to read a file which is inside the same (external) directory created by my own app?
The folder wasn't even there before, the app created it ... what's the point of preventing it from reading a static file inside it? isn't that a contradiction?

How did you go about adapting to these limitations that I think have been adopted only in part given my practical results ... what am I missing?
Can anyone explain to me what is happening?

For example this still seems to work on Android11:

 String PublicDirAccess = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
        //create new file directory object
        directory = new File(PublicDirAccess + "/" + UtiGlobal.getAppTitle(MyApp.getContext()) + "/");
        // if no directory exists, create new directory
        if (!directory.exists())
        {
            directory.mkdir();
            //MediaScannerConnection.scanFile(MyApp.getContext(), new String[] {directory.getAbsolutePath()}, null, null);
            forceMediaScanner(MyApp.getContext(), directory);
        }

But reading the documentation shouldn't work ... it shouldn't create the folder ... or not?

But then if I try to read a file inside it like this:

 BufferedReader reader = new BufferedReader(new InputStreamReader(mystreamInDownloadFolder));
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null)
        {
          sb.append(line).append("\n");
        }
        reader.close();

        StringOut= sb.toString();

It gives me the error: EACCES (Permission denied)

But if it makes me create the folder why then it prevents me from reading in it? ... wouldn't it have been more right that the app could continue reading in a folder created by its code? Even if it is in the external directory.

My question is simple:
Is this normal? I know very well that this should no longer be allowed but I don't understand why then the folder is created.

I add how to replicate the problem even more simply:

1) Create a folder in /storage/emulated/0/Download/Test
2) Create inside a test.txt file from the app
3) Modify the content of the file via usb PC, NETWORK or from Android using X-plore, Es-explorer, etc.

You just lost access to that file! ... so it will be impossible to transfer the files generated by my app as backups, csv, text files from one device to another? ... but is this normal?

0 Answers
Related