0

I found that android.webkit.CookieManagerworks since api level 9,so I think itwill work since android2.3 inclusive.But recently I found that it didn't work on android2.3.6。

//setcookie

CookieSyncManager.createInstance(this.activity);
CookieSyncManager.getInstance().startSync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
cookieManager.setCookie(cookie_url,cookieNameString);
CookieSyncManager.getInstance().sync();

I have tested it on android3.2 and android4.1.2,and it all works.

felicity
  • 1
  • 1

1 Answers1

0

I think you are seing an android bug:

https://code.google.com/p/android/issues/detail?id=16543

The removeAllCookie() call starts a thread, which then runs in parallell with the calling thread and may remove the cookies you are adding with setCookie(). A work-around is to only delete cookies for specific domains, if you know which those are.

It seems to have been fixed in newer android devices - I could not reproduce the problem on 4.1 or 4.2.

fornwall
  • 2,877
  • 3
  • 25
  • 38