Oh, after a few hours, I finally realized that it would work. Firstly CookieSyncManager depreciates in a later version of Android with api 21 according to doc.So decided not to use it anymore. Secondly, CookieManager is used to store cookies for WebView .
Final code
CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); List<Cookie> cookies = WSHelper.cookieStore.getCookies(); cookieManager.removeAllCookie(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookie.getName().contains("session")){ String cookieString = cookie.getName() + "=" + cookie.getValue() + "; Domain=" + cookie.getDomain(); cookieManager.setCookie(cookie.getDomain(), cookieString); Log.d("CookieUrl",cookieString + " "); } } } webView.loadUrl(url);
Key changes to the solution are the use of cookie.getDomain () instead of an explicit domain.
cookieManager.setCookie(cookie.getDomain(), cookieString);
source share