native登录,然后同步cookie到h5,避免多次登录时。遇到native退出登录,并清空缓存后,webview的登录状态一直没法清除。
经过反复调试,对/data/data/包名/app_webview目录下的文件各种删减测试,发现有些状态是被保存在Local Storage文件夹下,
需要额外再清空这个文件夹下的内容(android中对应的方法WebStorage.getInstance().deleteAllData();)。
完整清除cookie代码:
public static void clearCookies(Context context) {
CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
if (BuildVersionCodes.isSdkAccessible(BuildVersionCodes.LOLLIPOP_MR1)) {
cookieManager.removeAllCookies(null);
CookieManager.getInstance().flush();
} else {
cookieManager.removeAllCookie();
CookieSyncManager.getInstance().sync();
}
WebStorage.getInstance().deleteAllData();
}