Created
September 23, 2015 01:39
-
-
Save Sammiches327/c8c6fd30ceac05db0620 to your computer and use it in GitHub Desktop.
Clear app cache on Android devices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void clearApplicationData() { | |
File cache = getCacheDir(); | |
File appDir = new File(cache.getParent()); | |
if (appDir.exists()) { | |
String[] children = appDir.list(); | |
for (String s : children) { | |
if (!s.equals("lib")) { | |
deleteDir(new File(appDir, s)); | |
} | |
} | |
} | |
} | |
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment