1

As per the Documentation

Use scoped storage unless your app needs access to a file that's stored outside of an app-specific directory and outside of a directory that the MediaStore APIs can access. If you store app-specific files on external storage, you can make it easier to adopt scoped storage by placing these files in an app-specific directory on external storage. That way, your app maintains access to these files when scoped storage is enabled.

In my case I am creating a text file using below:

File root = new File(this.getExternalFilesDir(null), "sample");
    if (!root.exists()) {
        root.mkdirs();
    }
File file = new File(root, "sample.txt");

Above is creating a file at below location (while having NO SD card available):

/storage/emulated/0/Android/data/<package-name>/files/sample.txt

And I am performing writing operations on it.

Below are the queries:

  1. While referring to the mentioned documents it is still not cleared if Scoped storage enforcement is applicable for the above-mentioned scenario? Do I need to implement the Scoped Storage or It will work without any changes and there is no impact of Android 11 behavior change.

  2. As per my understanding There ks no Impact of Scoped storage enforcement due to Android 11. As I don't have the use case where the app needs access to a file that's stored outside of an app-specific directory. Is this understanding correct?

  3. In case if I want to read a file that is placed under the Downloads folder, I need to implement the Scoped Storage because my app wants to access the file which is stored outside of an app-specific directory. Is this understanding correct?
Hey You
  • 303
  • 3
  • 16
  • I think your assumptions are right. And i don't recall having problems with security reaching external app files. And yes If you want to get files from Scoped storage. You will have a bad time and even worse if you actually work with various files whom extensions is recognized just as 'application/octet-stream'. – Alpha Apr 20 '20 at 06:53
  • read this https://stackoverflow.com/a/66366102/9917404 – Thoriya Prahalad Feb 25 '21 at 09:50

1 Answers1

0

You are definitely allowed to make and access files in /storage/emulated/0/Android/data/ using the File API. As far as I can tell there's no change to those locations. I have done it.

For access to files in Download yes, scoped storage is required from what I've read. I haven't tested this but the docs are pretty clear that it's the law in Android 11. A bad law, but the law nonetheless.

Al Ro
  • 466
  • 2
  • 11
  • i just tested this. Created an image using another app - an image to toon generator - and put it in that app's folder. My Android 13 device and app is still able to access that image, despite it being created by another app. I also put a copy in the download folder. That, too, I can access and read, despite it not being created by the app. If its a law, its not very well enforced – Martin Jan 12 '23 at 21:34