Android WebView清空快取
阿新 • • 發佈:2018-11-29
Android原生和H5混合開發,要求使用者退出登入後清空H5所有的快取;
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(); //清空WebView的localStorage
https://stackoverflow.com/questions/14653916/deleting-localstorage-but-still-persists