How to clear all WebView stored information?

前端 未结 2 605
无人及你
无人及你 2021-02-06 15:09

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.clear         


        
相关标签:
2条回答
  • Found the solution:

    WebStorage.getInstance().deleteAllData();
    
    0 讨论(0)
  • 2021-02-06 15:59

    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();
        }
    }
    
    0 讨论(0)
提交回复
热议问题