开发者

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.

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?


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).


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜