CookieSyncManager

Android WebView保存Cookie登录

爱⌒轻易说出口 提交于 2020-04-13 00:59:55
因项目需要,需要在App中嵌入网页,使用Nativie方式登录,然后将cookie保存到WebView中,实现免登录功能。同步Cookie到WebView的方法网上有大量的参考资料,也可以参考下面的代码: /** * Sync Cookie */ private void syncCookie(Context context, String url){ try{ Log.d("Nat: webView.syncCookie.url", url); CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie();// 移除 cookieManager.removeAllCookie(); String oldCookie = cookieManager.getCookie(url); if(oldCookie != null){ Log.d("Nat: webView.syncCookieOutter.oldCookie", oldCookie); } StringBuilder sbCookie =