I want to make an Android App which will clean the cache of other apps. I have figured out how to do that for Android Version below Marshmallow.
This is what I am using for Android Honeycom and above:
if (isExternalStorageWritable()) {
final File externalDataDirectory = new File(Environment
.getExternalStorageDirectory().getAbsolutePath(), "/Android/data");
final String externalCachePath = externalDataDirectory.getAbsolutePath() +
"/%s/cache";
if (externalDataDirectory.isDirectory()) {
final File[] files = externalDataDirectory.listFiles();
for (File file : files) {
if (!deleteDirectory(new File(String.format(externalCachePath,
file.getName())), true)) {
Log.e(TAG, "External storage suddenly becomes unavailable");
return false;
}
}
} else {
Log.e(TAG, "External data directory is not a directory!");
}
} else {
Log.d(TAG, "External storage is unavailable");
}
But I am having an issue to figure out how to do it for Android Version Marshmallow and above.
Other cache cleaners present in the market are able to perform this by taking accessibility permission or any other way?
adb shell
(not root) thatrm -rf /sdcard/Android/data/com.google.android.apps.maps/cache
still works on Pie.