title: Clear cache of other applications in android not duplicate
body: <p>Hi I'm trying to clean other applications cache from my application, I'm able to clear other apps cache now till 4.1.2 version of android using the following code</p>
  
  <pre><code>import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import android.app.Activity;
  import android.content.pm.IPackageDataObserver;
  import android.content.pm.PackageManager;
  import android.os.Bundle;
  import android.widget.TextView;
  
  public class CacheNukerActivity extends Activity {
  private static final long ALL_YOUR_CACHE_ARE_BELONG_TO_US=1000000000L;
  private CachePackageDataObserver mClearCacheObserver;
  private TextView tv=null;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  tv=(TextView)findViewById(R.id.status);
  tv.setText("Clearing cache...");
  
  clearCache();
  }
  
   private final void clearCache() {
  if (mClearCacheObserver == null) {
    mClearCacheObserver=new CachePackageDataObserver();
  }
  
  PackageManager mPM=getPackageManager();
  
  @SuppressWarnings("rawtypes")
  final Class[] classes= { Long.TYPE, IPackageDataObserver.class };
  
  Long localLong=Long.valueOf(ALL_YOUR_CACHE_ARE_BELONG_TO_US);
  try {
    Method localMethod=
        mPM.getClass().getMethod("freeStorageAndNotify", classes);
  
    try {
      localMethod.invoke(mPM, localLong, mClearCacheObserver);
    }
    catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    catch (InvocationTargetException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  catch (NoSuchMethodException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
  }
  }
  
  private class CachePackageDataObserver extends
    IPackageDataObserver.Stub {
  public void onRemoveCompleted(String packageName, boolean succeeded) {
    tv.post(new Runnable() {
      public void run() {
        tv.append(" cache cleared");
      }
    });
  }
  }
  }
  </code></pre>
  
  <p>and the <code>IPackageDataObserver</code> code is</p>
  
  <pre><code>package android.content.pm;
  
  oneway interface IPackageDataObserver {
      void onRemoveCompleted(in String packageName, boolean succeeded);
  }
  </code></pre>
  
  <p>But when I run the same application in 4.2 and above android version, cache is not clearing. Please someone help me.</p>