一、清除Cookie
//clearCookies CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();
二、删除缓存文件
//clearCacheFile File file = new File(cacheDir); if (file != null && file.exists() && file.isDirectory()) { for (File item : file.listFiles()) { item.delete(); } // file.delete(); } context.deleteDatabase("webview.db"); context.deleteDatabase("webviewCache.db");
三、只删除和特定url关联的cookie呢
CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie();//移除cookie cookieManager.setCookie(url, cookieString);// 设置cookie
CookieSyncManager.getInstance().sync();// 同步cookie//使用setCookie(url, value)将指定url关联的cookie设为空串,只是在已有的基础上继续添加cookie,并不能重置已有的cookie。