Android CookieManager

AdamM picture AdamM · May 8, 2012 · Viewed 7k times · Source

I have an application that makes several web calls in order to get authenticated after which a JSON is returned. My web calls are to an https server and I am using HTTPURlConnection.

I need to store the session in a cookie, after researching around, I found this

http://developer.android.com/reference/java/net/HttpURLConnection.html

Under the sessions with cookies header, it tells you to use this code here

   CookieManager cookieManager = new CookieManager();
   CookieHandler.setDefault(cookieManager);

However when I try using this code, the new CookieManager(); part highlights in red and says

The constructor CookieManager is not visible

and the Cookiehandler.setDefault also highlights in red and says

The method setDefault(CookieHandler) in the type CookieHandler is not applicable for the arguments (CookieManager)

Does anyone know why this is?

Thanks in advance!

Answer

wattostudios picture wattostudios · May 8, 2012

You're probably trying to use the wrong CookieManager class. In Android there are 2 classes...

android.webkit.CookieManager
java.net.CookieManager

For this context, you need to use the java.net.CookieManager class.