如何在Android 10中创建公用文件夹/文件 [英] How to create a public folder/file in Android 10
问题描述
Android Api 29在文件和文件夹方面有很大的变化.到目前为止,我还没有找到在公共可见的内部存储中创建文件夹的方法.我创建的每个文件夹只能由我的应用查看.
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.
我编写了一个应用程序,该应用程序创建了应由其他应用程序(例如,Total Commander)将其复制到目标位置的数据文件.在激活Api 29之前,一切正常.我的某些客户端确实使用像素电话,而他们使用的是Android 10.
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.
如何在Android 10中创建公开的文件夹和文件?
How can I create a folder and files in Android 10 that are public?
已弃用:
Environment.getExternalStorageDirectory();
Environment.getExternalStoragePublicDirectory(type);
当我使用
File root = context.getExternalFilesDir(null);
创建的文件只能由我的应用查看.如何实现在Android 10之前有效的行为?
The created files can only be seen by my app. How can I achieve the behavior that was valid before Android 10?
提前谢谢.
推荐答案
当我使用
File root = context.getExternalFilesDir(null);
创建的文件只能由我的应用查看
when I use
File root = context.getExternalFilesDir(null);
The created files can only be seen by my app
如果用户选择了您放置在该目录中的文档,则任何使用Storage Access Framework的应用程序(例如 ACTION_OPEN_DOCUMENT
)都可以看到它们.
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
除了受限制的目录(例如 getExternalFilesDir()
或通过非文件系统手段( ACTION_OPEN_DOCUMENT
, MediaStore
).
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
).
如何在Android 10中创建公开的文件夹和文件?
How can I create a folder and files in Android 10 that are public?
在 Context
上使用 getExternalFilesDir()
和相关方法.或者,使用 ACTION_CREATE_DOCUMENT
或 ACTION_OPEN_DOCUMENT_TREE
并使用存储访问框架.无论哪种情况,生成的文档都可以由其他同时使用Storage Access Framework的应用程序使用.
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.
这篇关于如何在Android 10中创建公用文件夹/文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!