0
我使用此鏈接How to programmatically calculate all cache size of installed application?獲得了所有應用程序緩存大小。現在我需要清除所有緩存數據。那麼請告訴我如何清除所有應用程序緩存?清除android中的所有應用程序緩存
我使用此鏈接How to programmatically calculate all cache size of installed application?獲得了所有應用程序緩存大小。現在我需要清除所有緩存數據。那麼請告訴我如何清除所有應用程序緩存?清除android中的所有應用程序緩存
請嘗試使用以下代碼。
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 * 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;
}
}
你需要有這個在你的清單:
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
我希望它會工作的
此代碼不適用於我.. –
可能重複[清除緩存安裝在移動所有的應用程序(HTTP:// stackoverflow.com/questions/30619209/clear-cache-for-all-application-installed-on-mobile) – 2Dee