Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android CookieManager

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!

like image 600
AdamM Avatar asked May 08 '12 14:05

AdamM


People also ask

What is CookieManager?

A CookieManager class's instances provide a concrete implementation of CookieHandler. It separates the storage of cookies from the policy surrounding accepting and ignoring cookies.

How do I clear cookies on Webview Android?

Open your browser. Android browser: Go to Menu > More > Settings or Menu > Settings > Privacy & Security. Chrome: Go to Menu > Settings > Privacy. Android browser: Tap Clear cache, Clear history, and Clear all cookie data as appropriate.


1 Answers

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.

like image 105
wattostudios Avatar answered Sep 20 '22 15:09

wattostudios