I want to clear the cache memory of all other installed applications. Please provide me some solution of the problem.
1 Answers
The simple answer:
You can't.
The more complex/accurate answer:
There is permission android.permission.GET_TASKS that is a signature-level permission that can allow an app to do this. However, as it is a signature-level permission it means it can only be used in system/firmware apps.
Edit:
I seem to have misinterpreted the question - the above is valid if you are trying to clear cached applications (i.e. recent apps)
To clear all installed application's caches the answer below (based off this previous answer) is apparently correct - please note the answer there incorrect tries to call freeStorage and not freeStorageAndNotify in the reflection:
PackageManager pm = getPackageManager();
// Get all methods on the PackageManager
Method[] methods = pm.getClass().getDeclaredMethods();
for (Method m : methods) {
if (m.getName().equals("freeStorageAndNotify")) {
// 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;
}
}
Also make sure to add the following permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
-
But hundred applications are on play store which are clearing cache. how they are doing this??? for example u can see the following link https://play.google.com/store/apps/details?id=mobi.infolife.cache – Muhamad Umair Anwar Apr 02 '15 at 15:30
-
Ah I may have misinterpreted your question - see [here](http://stackoverflow.com/questions/14507092/android-clear-cache-of-all-apps) for an example of what you are after – Ed George Apr 02 '15 at 15:32
-
i have tried this code and follow the instruction which was given in the comment in that solution but it is not working. please can u test the code? – Muhamad Umair Anwar Apr 02 '15 at 18:05
-
I find out the solution.. above code is working fine on below 4.2, on 4.2 and above it doesn't clear complete cache. – Muhamad Umair Anwar Apr 03 '15 at 17:45