【发布时间】:2020-06-10 05:23:29
【问题描述】:
我使用此代码清除已安装应用程序的缓存数据,它在有根设备上完美运行:
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;
}
}
但此代码仅适用于已安装的应用程序,不适用于系统安装的应用程序(例如画廊),我想以编程方式清除画廊应用程序的缓存,例如以下操作: Clear Gallery Cache
【问题讨论】:
-
使用this method 清除所有应用缓存
标签: java android caching gallery