Android WebView清空缓存

Android 混合开发,要求用户退出登录后清空cookie和所有的缓存;

1、清空Cookie

CookieSyncManager.createInstance(context.getApplicationContext());
CookieManager cookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    cookieManager.removeSessionCookies(null);
    cookieManager.removeAllCookie();
    cookieManager.flush();
} else {
    cookieManager.removeSessionCookies(null);
    cookieManager.removeAllCookie();
    CookieSyncManager.getInstance().sync();
}

2、清空Localstorage;
清空H5保存在本地的所有内容;

WebStorage.getInstance().deleteAllData();

转自:https://blog.csdn.net/qq_35605213/article/details/82661347


58 Clicks !

发表评论

电子邮件地址不会被公开。