Android SD卡存储有什么约定吗?

发布于 2024-10-06 03:29:36 字数 175 浏览 1 评论 0 原文

在安装了很多应用程序并自己构建了一些应用程序之后,我相信很多人都对此感到好奇。如果我查看我的 SD 卡,它看起来绝对可怕,而且很难找到属于我的用于将音乐/视频/图片放在不同应用程序的所有文件夹之间的文件夹。

这里是否有任何约定,我们,开发人员,应该尝试将他们的应用程序放入一个基本文件夹中,或者谷歌已经完全忘记了这一点?

After installing a lot of apps, and building a few myself, I'm sure many people have been wondering about this. If I'm looking through my SD card it looks absolutely horrible, and its really hard to find folders that are mine for putting music/videos/pictures in between all the folders for different applications.

Is there any conventions here that we, the developers, should try to put their apps into one base folder or has Google forgot about this completely?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心头的小情儿 2024-10-13 03:29:36

来自参考

应用程序不应直接使用此顶级目录,以避免污染用户的根命名空间。应用程序私有的任何文件都应放置在 Context.getExternalFilesDir,如果应用程序被卸载,系统将负责删除它。其他共享文件应放置在 获取ExternalStoragePublicDirectory(字符串)。

From reference:

Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace. Any files that are private to the application should be placed in a directory returned by Context.getExternalFilesDir, which the system will take care of deleting if the application is uninstalled. Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory(String).

不喜欢何必死缠烂打 2024-10-13 03:29:36

我在我的应用程序中扩展了 Application 类并具有以下内容...

protected static File myAppDir = null;

然后在 onCreate() (在应用程序中)...

if (myAppDir == null)
    myAppDir = new File(getExternalFilesDir(null).getAbsolutePath());

这会自动创建 /mnt/sdcard/Android/data/com.mycompany.myApp/files 如果没有不存在。您可以向 getExternalFilesDir() 提供“null”以外的其他参数,以获取图片、视频等内容。

I extend the Application class in my app and have the following...

protected static File myAppDir = null;

Then in onCreate() (in the Application)...

if (myAppDir == null)
    myAppDir = new File(getExternalFilesDir(null).getAbsolutePath());

This automatically creates /mnt/sdcard/Android/data/com.mycompany.myApp/files if it doesn't exist. You can supply other parameters than 'null' to getExternalFilesDir() for things like pictures, videos etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文