title: How to delete other applications cache from our android app?
body: <p>I'm trying to develop an android app that could erase others application cache data, I tried to browse through all blogs but none of them worked for me, I can able to clear my application's cache by the following code</p>
  
  <pre><code>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));
                          Toast.makeText(DroidCleaner.this, "Cache Cleaned", Toast.LENGTH_LONG).show();
                          Log.i("TAG", "**************** File /data/data/APP_PACKAGE/" + s + " DELETED *******************");
                      }
                  }
              }
  
  public static boolean deleteDir(File dir) 
  {
      if (dir != null &amp;&amp; dir.isDirectory()) 
      {
          String[] children = dir.list();
          for (int i = 0; i &lt; children.length; i++) 
          {
              boolean success = deleteDir(new File(dir, children[i]));
              if (!success) 
              {
                  return false;
              }
          }
      }
      return dir.delete();
  }
  </code></pre>
  
  <p>My manifest code</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CLEAR_APP_CACHE"/&gt;
  </code></pre>
  
  <p>I tested the code on 2.2, 2.3 and 4.0</p>
  
  <p>and after seeing the post in the following link <a href="https://stackoverflow.com/questions/14507092/android-clear-cache-of-all-apps">Android: Clear Cache of All Apps?</a></p>
  
  <p>I changed my code to </p>
  
  <pre><code>PackageManager  pm = getPackageManager();
  // Get all methods on the PackageManager
  Method[] methods = pm.getClass().getDeclaredMethods();
  for (Method m : methods) {
      if (m.getName().equals("freeStorage")) {
          // Found the method I want to use
          try {
              long desiredFreeStorage = 8 * 1024 * 1024 * 1024; // Request for 8GB of free space
          m.invoke(pm, desiredFreeStorage , null);
      } catch (Exception e) {
          // Method invocation failed. Could be a permission problem
      }
      break;
     }
  }
  </code></pre>
  
  <p>I want to clear other application's cache, can any body please help me, please correct me if I'm wrong, Thanks in advance.</p>