简体   繁体   English

Android SD卡存储有任何约定吗?

[英]Is There Any Convention for Android SD Card Storage?

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. 如果我正在查看我的SD卡,它看起来绝对可怕,而且很难找到可以在不同应用程序的所有文件夹之间放置音乐/视频/图片的文件夹。

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? 在这里,我们(开发人员)是否应该尝试将其应用程序放在一个基本文件夹中,或者Google完全忘记了这些约定?

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. 应将应用程序专用的所有文件放在Context.getExternalFilesDir返回的目录中,如果卸载了应用程序,系统将负责删除该目录。 Other shared files should be placed in one of the directories returned by getExternalStoragePublicDirectory (String). 其他共享文件应放在getExternalStoragePublicDirectory (字符串)返回的目录之一中。

I extend the Application class in my app and have the following... 我在我的应用程序中扩展了Application类,并具有以下内容...

protected static File myAppDir = null;

Then in onCreate() (in the Application)... 然后在onCreate()中(在应用程序中)...

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. 如果/mnt/sdcard/Android/data/com.mycompany.myApp/files不存在,它将自动创建。 You can supply other parameters than 'null' to getExternalFilesDir() for things like pictures, videos etc. 您可以为图片,视频等内容向getExternalFilesDir()提供除“ null”以外的其他参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM