Java Question clearcache kitkat

mohsen nasrabady

Active Member
Licensed User
Longtime User
this code clear all cache apps before kitkat
any solution for delete cache on kitkat?

B4X:
       PackageManager  pm = BA.applicationContext.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 = 100 * 1024 * 1024 * 1024; // Request for 100GB of free space
                m.invoke(pm, desiredFreeStorage , null);
            } catch (Exception e) {
                BA.Log(e.getMessage());
                // Method invocation failed. Could be a permission problem
            }
            break;
        }
    }
 

Informatix

Expert
Licensed User
Longtime User
this code clear all cache apps before kitkat
any solution for delete cache on kitkat?

B4X:
       PackageManager  pm = BA.applicationContext.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 = 100 * 1024 * 1024 * 1024; // Request for 100GB of free space
                m.invoke(pm, desiredFreeStorage , null);
            } catch (Exception e) {
                BA.Log(e.getMessage());
                // Method invocation failed. Could be a permission problem
            }
            break;
        }
    }
Did you add this permission to your manifest?
"android.permission.CLEAR_APP_CACHE"
 

mohsen nasrabady

Active Member
Licensed User
Longtime User
yes my wrong sorry
but in markets even in iran there is very apps that can clear cache
i think some method like this not publish in network (stockoverflow ....) for some reason (maybe money)
 
Top