/** * @param context * 删除缓存 */ public static void clearAllCache(Context context) { deleteDir(context.getCacheDir()); if (Environment.getExternalStorageState().equals( Environment.MEDIA_MOUNTED)) { deleteDir(context.getExternalCacheDir()); } } private static boolean deleteDir(File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); int size = 0; if (children != null) { size = children.length; for (int i = 0; i < size; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; } } } } if (dir == null) { return true; } else { return dir.delete(); } }