Android开发中,有时需要知道cache缓存的路径。我写了一个静态类,供大家能参考
public class CommonUtil {
/**
* 获取cache路径
*
* @param context
* @return
*/
public static String getDiskCachePath(Context context) {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) {
return context.getExternalCacheDir().getPath();
} else {
return context.getCacheDir().getPath();
}
}
}