title: How to delete app cache for all apps in Android M?
body: <p>Is there an option to delete the cache of all Apps or certain Apps in Android M ? </p>
  
  <p>Seems like most ways don't work anymore in Android M. </p>
  
  <p>As a reference I used this Code out of this discussion : 
  <a href="https://stackoverflow.com/questions/14507092/android-clear-cache-of-all-apps/14509140?noredirect">Android: Clear Cache of All Apps?</a></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>Combined with this permission</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CLEAR_APP_CACHE"/&gt;
  </code></pre>
  
  <p>This Code works fine on devices lower than Android 6.0. But on devices with Android 6.0 it results in this exception </p>
  
  <pre><code>java.lang.IllegalArgumentException: Wrong number of arguments; expected 3, got 2 
  </code></pre>
  
  <p>There is an open source cleaner on GitHub, which stopped development with this reason: </p>
  
  <blockquote>
    <blockquote>
      <p>Partial incompatibility with Android 6.0 and newer</p>
    </blockquote>
    
    <p>Starting with Android 6.0,  CLEAR_APP_CACHE  permission seems to be no
    longer available to regular applications and since this permission is
    required for cleaning of internal cache, Cache Cleaner is not able to
    clean internal cache on Android 6.0 and newer. However, cleaning of
    external cache is still supported.</p>
  </blockquote>
  
  <p>Is there really no way, to delete App Cache on devices with Android M ?</p>
  
  <p><strong>How does the Google Setting App handle it ?
  It can't be the new method:</strong> </p>
  
  <pre><code>public abstract void freeStorage(String volumeUuid, long freeStorageSize,
          IntentSender pi)
  </code></pre>
  
  <p><strong>because I think it does not delete the Cache of certain apps, but of enough apps to clear the expected ram size... But the Settings app can clear the Cache of certain apps</strong> </p>
  
  <p><strong>UPDATE</strong>
  Like the excepted answer explains, there seems to be no way to delete tha App Cache without root on Devices with Android M and above. But I will post it here if I find a way....</p>