读书人

Android中关于外部储存的一些重要函数

发布时间: 2012-10-19 16:53:36 作者: rapoo

Android中关于外部存储的一些重要函数
一、简介关于Android的数据外部存储,在API Level 8之前,所有的文件都是建议放在Environment.getExternalStorageState()目录下的;从API Level 8开始,对于应用程序的私有文件应该放在Context.getExternalFilesDir目录下,非私有的(shared)的文件应该放在目录下Environment.getExternalStoragePublicDirectory(String)所指定的目录下。对于缓存文件应该放在Context.getExternalCacheDir()目录下。另外在准备把数据保存外部存储之前应该先通过Environment.getExternalStorageState()获取其状态,再根据其状态确定其是否可用,如果不可用,可以考虑将数据保存在内部存储中。关于Android的内部存储可以参照《Android中关于内部存储的一些重要函数》二、Context中关于外部存储的重要函数

public abstract File getExternalCacheDir ()Since: API Level 8

Returns the absolute path to the directory on the external filesystem (that is somewhere on Environment.getExternalStorageDirectory() where the application can place cache files it owns.

This is like getCacheDir() in that these files will be deleted when the application is uninstalled, however there are some important differences:

该函数像getCacheDir() 一样,保存在该目录下的文件会在卸载该应用程序时被删除。然而又有以下几点不同:

读书人网 >Android

热点推荐