如何清除所有WebView存储的信息?

How to clear all WebView stored information?

我有一个 Android 浏览器,我可以选择清除缓存、存储、cookie 等。

代码如下所示:

webView.clearCache(true);
webView.clearFormData();
webView.clearHistory();
webView.clearSslPreferences();
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();

这似乎适用于我的所有测试,但是当我转到 google.com 时,我的旧搜索仍然存在。我没有清除什么?

谢谢。

找到解决方案:

WebStorage.getInstance().deleteAllData();

我有一个 root-access 授予的设备,发现调用 WebStorage.getInstance().deleteAllData(); 和类似的代码不会清除 WebView 在 [=15] 创建的 cache =].

此外,该代码有时会导致致命错误,例如 A/libc: Send stop signal to pid:16145 in void debuggerd_signal_handler(int, siginfo_t*, void*)

而且它(缓存)的大小也不小。

为此,您可以使用以下代码片段:

public static void clearWebViewCachesCustom(Context context) {
    try {
        String dataDir = mContext.getPackageManager().getPackageInfo(context.getPackageName(), 0).applicationInfo.dataDir;
        new File(dataDir + "/app_webview/").delete();
    } catch (Exception e) {
        if (!MainActivity.deBugTest) Crashlytics.logException(e);
        e.printStackTrace();
        e.getSuppressed();
    }
}