Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CookieManager and CookieSyncManager not syncing cookies to webview in ICS (works on all previous API levels)

Background:

I'm acquireing cookies through my app and use them internally by making requests to http. Users can switch to webview any given time, in which case I sync/inject cookies to webView.

Code for synchronizing cookies to webview using CookieSyncManager:

CookieSyncManager.createInstance(a);
CookieManager cm = CookieManager.getInstance();
cm.setCookie(domain, cookieName + "=" + cookieValue);
CookieSyncManager.getInstance().sync();

This works on all API levels except API 15+ (Android 4.0, Ice Cream Sandwich). The CookieManager API is not deprecated.

What is causing this problem and are there any workarounds?

like image 872
Indrek Kõue Avatar asked Mar 14 '12 09:03

Indrek Kõue


2 Answers

I had the same problem recently which I found was my mistake. The problem was the way I set the domain (but it worked till API 15). Try to prefix the domain with the dot: ".company.com" instead of "company.com".

like image 143
TheVoid Avatar answered Nov 09 '22 13:11

TheVoid


You can try the Apache DefaultHttpClient to do this work for you, I don't think it been changed in Ice Cream Sandwich.

I found this sample, but there is lots more in here

like image 22
Ilya Gazman Avatar answered Nov 09 '22 11:11

Ilya Gazman