Android Api 29 has big changes regarding files and folders. I have not found a way so far to create a folder in the internal storage that is public visible. Every folder I create can be seen by my app only.
I write an app that creates data files that shall be picked up by other apps, for instance the Total Commander to copy them to a destination. Everything worked fine until I activated Api 29. Some of my clients DO use pixel phones and they use Android 10.
How can I create a folder and files in Android 10 that are public?
This has been deprecated:
Environment.getExternalStorageDirectory();
Environment.getExternalStoragePublicDirectory(type);
and when I use
File root = context.getExternalFilesDir(null);
The created files can only be seen by my app. How can I achieve the behavior that was valid before Android 10?
Thanks in advance.
How can I create a folder and files in Android 10 that are public? Use getExternalFilesDir () and related methods on Context. Or, use ACTION_CREATE_DOCUMENT or ACTION_OPEN_DOCUMENT_TREE and use the Storage Access Framework. In either case, the resulting documents can be used by other apps that also use the Storage Access Framework. Thanks.
Access the home screen panel where the apps you want to put into a folder are located. Drag the first app and drop it on top of another and this will create a folder with both apps inside. Tap the folder to view the apps in it.
1 Open the file manager app on your phone. 2 Navigate to the directory where you want to make a new folder. ... 3 Once you’re in your preferred directory, tap the three-dots menu at the top-right corner and select New folder . 4 Enter a name for your folder and tap OK . 5 Your folder is now created.
Navigate to the directory where you want to make a new folder. This directory could be on your internal storage or even on external storage like an SD card. Once you’re in your preferred directory, tap the three-dots menu at the top-right corner and select New folder .
when I use
File root = context.getExternalFilesDir(null);
The created files can only be seen by my app
They can be seen by any app that uses the Storage Access Framework (e.g., ACTION_OPEN_DOCUMENT
), if the user chooses the document that you place in that directory.
I write an app that creates data files that shall be picked up by other apps
Other apps have no access to external or removable storage on Android 10, except in the limited directories like getExternalFilesDir()
or via non-filesystem means (ACTION_OPEN_DOCUMENT
, MediaStore
).
How can I create a folder and files in Android 10 that are public?
Use getExternalFilesDir()
and related methods on Context
. Or, use ACTION_CREATE_DOCUMENT
or ACTION_OPEN_DOCUMENT_TREE
and use the Storage Access Framework. In either case, the resulting documents can be used by other apps that also use the Storage Access Framework.
Starting from Android 10, you should use SAF, and let user choose the directory using ACTION_OPEN_DOCUMENT_TREE
.
If you need a simple example. You can find it here
Alternatively, you could use requestLegacyExternalStorage = true
in manifest when your app is not newly released. But, this is something that should not be used for future release, as this is a short-term solution provided by Google.
Note: In future releases of Android, user will not be able to pick the whole external file directory and Downloads directory, so unfortunately, keep in mind that we are not going to have access to these as well! For more information you can click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With