Java tutorial
//package com.java2s; import android.content.Context; import android.os.Environment; import java.io.File; public class Main { 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) { return false; } if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; } } } return dir.delete(); } }