Last active
December 11, 2015 21:39
-
-
Save khris/4664150 to your computer and use it in GitHub Desktop.
Cookie synchronization between WebView and HttpClient
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CookieManager cookieManager = CookieManager.getInstance(); | |
BasicCookieStore cookieStore = new BasicCookieStore(); | |
final String appDomain = mContext.getResources().getString(R.string.app_domain); | |
String cookies = cookieManager.getCookie(appDomain); | |
String[] splitCookies = cookies.split(";"); | |
for (String cookie : splitCookies) { | |
String[] cookieParts = cookie.split("="); | |
if (cookieParts.length > 0) { | |
String cookieValue = ""; | |
if (cookieParts.length >= 2) { | |
cookieValue = cookieParts[1]; | |
} | |
BasicClientCookie newCookie = new BasicClientCookie(cookieParts[0].trim(), cookieValue); | |
cookieStore.addCookie(newCookie); | |
} | |
} | |
cookieManager.removeExpiredCookie(); | |
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment