Cache and temp files/folders remove android
02:45 05 Mar 2013

Hi friend thanks for previous replies, i am facing problem in removing cache and temp files/folders, what i require is to clean the whole device temp files and cache from one app which is mine app but here i am able to clean only my apps cache , here is my code

 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());

    }  

and my clear cache method as under

 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;
      }

please help how can i clear the whole device cache,here i am getting every apps cache location i.e. dir to cache of all apps in device but when i want to delete them it returns false

please help any help is appreciable

i am able to clear cache of one app which is the one i am running this code but not for other apps

thanks in advance

android caching