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);
}