How to clear all WebView stored information?

柔情痞子 提交于 2020-08-01 05:21:24

问题


I have an Android browser and I have the option to clear cache, storage, cookies, etc.

The code looks like this:

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

And this seems to work on all my tests but when I go to google.com my old searches are still there. What am I not clearing?

Thanks.


回答1:


Found the solution:

WebStorage.getInstance().deleteAllData();



回答2:


I have got a root-access granted device and found that calling WebStorage.getInstance().deleteAllData(); and similar codes doesn't clear the cache created by the WebView at applicationDatadir/app_webview.

Also, that codes sometimes causes fatal errors like A/libc: Send stop signal to pid:16145 in void debuggerd_signal_handler(int, siginfo_t*, void*)

And it's (the cache) not so small in size.

To achieve that you can use this following code snippet :

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();
    }
}


来源:https://stackoverflow.com/questions/44502450/how-to-clear-all-webview-stored-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!