How to create a public folder/file in Android 10

坚强是说给别人听的谎言 提交于 2020-01-11 11:50:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!