Clear Cache in Android Application programmatically
If you are looking for delete cache of your own application then simply delete your cache directory and its all done !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public static void deleteCache(Context context) { try { File dir = context.getCacheDir(); deleteDir(dir); } catch (Exception e) {} } public static boolean deleteDir(File dir) { 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(); } else if(dir!= null && dir.isFile()) { return dir.delete(); } else { return false; } } |
And you may require following permission to add in your manifest file in order to delete cache of other application
1 |
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/> |