1

I used this code to clear installed applications cached data, and it works perfectly on rooted device:

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; // Request for 8GB of free space
                m.invoke(pm, desiredFreeStorage , null);
                Toast.makeText(this, "Cache Cleared!", Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                txtView.setText(e.getMessage());
            }
            break;
        }
    }

But this code works with installed applications only, not for system installed apps Like (Gallery), i want to clear cache for a gallery app programmatically, like this action: Clear Gallery Cache

braX
  • 11,506
  • 5
  • 20
  • 33

1 Answers1

0

It is not possible on Non rooted device as Android doesn't allow it since Marshmallow, Please go through this ans for more details, https://stackoverflow.com/a/17334600/4032259

Max
  • 510
  • 5
  • 16