手机存储分为三块区域
1.内部存储
2.SD卡存储(Primary External Storage)
3.外置sd卡(Secondary External Storage)
内部存储
1.RAM 运行时内存
2.ROM 内部存储,即data目录
*Environment.getDataDirectory().getPath()
/data(没有root,无法打开)
1.app(存放着安装的apk)
2.data(APP的存储内容)
data/data/<包名>/shared_prefs
data/data/<包名>/databases
data/data/<包名>/files
data/data/<包名>/cache(context.getCacheDir())
3.mnt(挂载点)
4.dev(Linux系统文件夹)
5.system(系统配置)
Environment.getDownloadCacheDirectory().getPath()
/cache
Environment.getRootDirectory().getPath()
/system*
SD卡存储(可读写)
外部存储路径:
Environment.getExternalStorageDirectory().getPath()
/storage/emulated/0
九大公有目录:
Environment.getExternalStoragePublicDirectory(DIRECTORY_ALARMS) ;
//storage/emulated/0/Alarms
Environment.getExternalStoragePublicDirectory(DIRECTORY_DCIM);
//storage/emulated/0/DCIM
Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS);
//storage/emulated/0/Download
Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES);
//storage/emulated/0/Movies
Environment.getExternalStoragePublicDirectory(DIRECTORY_MUSIC);
//storage/emulated/0/Music
Environment.getExternalStoragePublicDirectory(DIRECTORY_NOTIFICATIONS);
//storage/emulated/0/Notifications
Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES);
//storage/emulated/0/Pictures
Environment.getExternalStoragePublicDirectory(DIRECTORY_PODCASTS);
//storage/emulated/0/Podcasts
Environment.getExternalStoragePublicDirectory(DIRECTORY_RINGTONES);
//storage/emulated/0/Ringtones
可通过context.getExternalFilesDir(String type)获取,也由上直接获取,不建设使用公有目录存储App数据
私有目录:
getExternalCacheDir()
//storage/emulated/0/Android/data/<包名>/cache/
context.getObbDir()
//storage/sdcard/Android/obb/
外置SD卡(可读,无法写入)
public static String getExtendedMemoryPath(Context mContext) {
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
try {
Class<?> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
Object result = null;
if (mStorageManager != null){
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
result = getVolumeList.invoke(mStorageManager);
}
Method getPath = storageVolumeClazz.getMethod("getPath");
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
final int length = Array.getLength(result);
for (int i = 0; i < length; i++) {
Object storageVolumeElement = Array.get(result, i);
String path = (String) getPath.invoke(storageVolumeElement);
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
if (removable) {
return path;
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
应用管理清除数据的清楚目录:
清除缓存:将外部私有数据下的cache包(/storage/emulated/0/Android/data/<包名>/cache)清除,将内部数据下的cache包下的内容(/data/data/<包名>/cache/)清除 。
清楚数据:将外部私有数据的data下包名(/storage/emulated/0/Android/data/<包名>/)清除,将内部数据包名下的所有内容(/data/data/<包名>/)清除;