I know about the existince of CookieManager, but how do I remove cookies of a domain only?
Can someone help me with some code fragment?
For security, you're not allowed to edit (or delete) a cookie on another site. Since there's no guarantee that you own both foo.domain.com and bar.domain.com , you won't be allowed to edit the cookies of foo.domain.com from bar.domain.com and vice versa.
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.
public void clearCookies(String domain) {
CookieManager cookieManager = CookieManager.getInstance();
String cookiestring = cookieManager.getCookie(domain);
String[] cookies = cookiestring.split(";");
for (int i=0; i<cookies.length; i++) {
String[] cookieparts = cookies[i].split("=");
cookieManager.setCookie(domain, cookieparts[0].trim()+"=; Expires=Wed, 31 Dec 2025 23:59:59 GMT");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With