问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/58345995/how-to-create-a-public-folder-file-in-android-10