Ich habe ein Problem beim Entfernen von Cache und temporären Dateien/Ordnern.
Was ich brauche, ist, die gesamten temporären Dateien und den Cache des Geräts von einer App zu bereinigen, die meine App ist
aber hier kann ich nur den Cache meiner Apps bereinigen, hier ist mein Code
Code: Select all
private void mAppMethod(List mApps) {
// TODO Auto-generated method stub
// File f = g
for (int i = 0; i < mApps.size(); i++) {
File dir = new File("/data/data/"+mApps.get(i).getPackageName().concat("/cache"));
Log.e("dir "+dir, "is directory "+dir.isDirectory());
int j = clearCacheFolder(dir, 10);
if (dir!= null && dir.isDirectory())
Log.e("j", "rff "+dir.delete());
System.out.println(j+" rff "+dir.delete());
}
Code: Select all
static int clearCacheFolder(final File dir, final int numDays) {
int deletedFiles = 0;
if (dir!= null && dir.isDirectory()) {
// System.out.println("here"+dir.delete());
Log.e("here", "here "+dir.isDirectory());
try {
Log.e("here1", "here1"+dir.listFiles());
for (File child:dir.listFiles()) {
Log.e("here11", "here11");
//first delete subdirectories recursively
if (child.isDirectory()) {
Log.e("here111", "here111");
deletedFiles += clearCacheFolder(child, numDays);
Log.e("here1111", "here1111");
}
Log.e("here11111", "here11111");
//then delete the files and subdirectories in this dir
//only empty directories can be deleted, so subdirs have been done first
if (child.lastModified() < new Date().getTime() - numDays * DateUtils.DAY_IN_MILLIS) {
Log.e("here111111", "here111111");
if (child.delete()) {
Log.e("here1111111", "here1111111");
deletedFiles++;
Log.e("here11111111", "here11111111");
}
}
}
}
catch(Exception e) {
Log.e("TAG", String.format("Failed to clean the cache, error %s", e.getMessage()));
}
}
return deletedFiles;
}
Mobile version