Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove specific cookie value?

In my app there are facebook and twitter login using browser and after login it stores cookies automatically. i have to logout facebook that will be happen to remove facebook cookies value but i don't know how to remove particular cookies.

if i remove all cookies using:

CookieManager cm = CookieManager.getInstance(this);
cm.removeAllCookies();

but it removes all cookies value means it will logout both facebook and twitter both.

my question is -- how to remove particular cookie value.

thanks..

like image 823
Archana Avatar asked Oct 18 '11 04:10

Archana


People also ask

How do you remove cookie values?

To delete a cookie, you just need to set the value of the cookie to empty and set the value of expires to a passed date.

How do I find the value of a specific cookie?

in order to retrieve specific cookie value, we just need to get string that is after "; {name}=" and before next ";". Before we do any processing, we prepend the cookies string with "; ", so that every cookie name, including the first one, is enclosed with "; " and "=": "; {name}={value}; {name}={value}; ..."

How do I clear cookies for a particular edge?

Delete cookies from a specific site In Edge, select Settings and more > Settings > Cookies and site permissions. Under Cookies and data stored, select Manage and delete cookies and site data > See all cookies and site data and search for the site whose cookies you want to delete.


1 Answers

You should use CookieManager.setCookie() and set the cookie to the empty string. Something like this should work:

String cookieString = "cookieName=''";
cookieManager.setCookie(cookieDomain, cookieString);

In addition to setting the cookie value to empty, you can also expire the cookie by setting the 'expire' value in the cookie string to a time in the past. For example:

String cookieString = "cookieName=;expires=Mon, 17 Oct 2011 10:47:11 UTC;";
like image 188
spatulamania Avatar answered Sep 28 '22 07:09

spatulamania