How can I clear the Android app cache?
<p>I am writing a app which can programatically clear application cache of all the third party apps installed on the device. Following is the code snippet for Android 2.2</p>

<pre><code>public static void trimCache(Context myAppctx) {

    Context context = myAppctx.createPackageContext("com.thirdparty.game", 
            Context.CONTEXT_INCLUDE_CO|Context.CONTEXT_IGNORE_SECURITY);

    File cachDir = context.getCacheDir();        
    Log.v("Trim", "dir " + cachDir.getPath());

    if (cachDir!= null &amp;&amp; cachDir.isDirectory()) {

        Log.v("Trim", "can read " + cachDir.canRead());
        String[] fileNames = cachDir.list();
        //Iterate for the fileName and delete
    }
}
</code></pre>

<p>My manifest has following permissions:</p>

<blockquote>
  <p>android.permission.CLEAR_APP_CACHE<br>
  android.permission.DELETE_CACHE_FILES</p>
</blockquote>

<p>Now the problem is that the name of the cache directory is printed but the list of files <code>cachDir.list()</code> always returns null. I am not able to delete the cache directory since the file list is always null. </p>

<p>Is there any other way to clear the application cache?  </p>
