1.实际路径:data/data/com.xx.xx/cache
mContext.getCacheDir()
2.实际路径:data/data/com.xx.xx/files 在应用信息中点击清除缓存不会清除此文件夹里的文件,点击清除数据才会清除,并清除cache文件夹内的文件
mContext.getFilesDir()
3.实际路径: sdcard/Anroid/data/com.xx.xx/cache
mContext.getExternalCacheDir()
4.实际路径:sdcard/Android/data/com.xx.xx/
mContext.getExternalFilesDir(null)
5.实际路径:sdcard/
Environment.getExternalStorageDirectory()
在应用管理里点击清除缓存会清除1,3文件夹里的数据,点击清除数据会清除上面四个文件夹里的所有数据,清除com.xx.xx下的所有数据;
1,2是包里的路径,3,4是内置sd卡的路径,/storage/sdcard0 = /storage/emulated/0/
外置sdk路径是/storage/sdcard1
/**
* 根据传入的uniqueName获取硬盘缓存的路径地址。
*/
public static File getSdcardCacheDir(String uniqueName) {
String cachePath;
if (Environment.MEDIA_MOUNTED.equals(Environment
.getExternalStorageState())
&& !Environment.isExternalStorageRemovable()) {
if (mContext.getExternalCacheDir() != null) {//小米某些盒子经过上面的判断后,这里依然可能为空
cachePath = mContext.getExternalCacheDir().getPath();
} else {
cachePath = mContext.getCacheDir().getPath();
}
} else {
cachePath = mContext.getCacheDir().getPath();
}
return new File(cachePath + File.separator + uniqueName);
}
/**
*
* @param fileName
* @return
*/
public static File getSdcardFileDir(String fileName) {
String path;
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) && !Environment.isExternalStorageRemovable()) {
File externalFilesDir = mContext.getExternalFilesDir(null);
if (externalFilesDir != null) {
path = externalFilesDir.getPath();
} else {
path = mContext.getFilesDir().getPath();
}
} else {
path = mContext.getFilesDir().getPath();
}
return new File(path + File.separator + fileName);
}
/**
* 清除缓存会清除的文件夹
*
* @param fileName
* @return
*/
public static File getAppCacheDir(String fileName) {
String cacheDir = mContext.getCacheDir().getPath();
return new File(cacheDir + File.separator + fileName);
}
/**
* 清除缓存不会清除,清除数据会清除
*
* @param uniqueName
* @return
*/
public static File getAppFileDir(String uniqueName) {
String cachePath = mContext.getFilesDir().getPath();
return new File(cachePath + File.separator + uniqueName);
}