I am trying to delete a specific cookie for a domain and seems impossible.
In a web view in onPageFinished
I can see the cookie and the relevant URL.
I am using the following code to delete the cookie:
CookieManager cm = CookieManager.getInstance();
final String url = "https://server.com/foo/index.html?bar=1"; // this is the URL is see in the `onPageFinished`
String cookiesString = cm.getCookie(url);
String [] cookies = cookiesString.split(";");
for(String cookie:cookies) {
String[] cookieParts = cookie.split("=");
if(cookieParts.length <= 0) {
continue;
}
if(cookieParts[0].trim().equals("xxxcookiename")) {
cm.setCookie(url, cookieParts[0] + "=0;");
}
else {
cm.setCookie(url, cookie);
}
}
cm.flush();
What this does is append a `xxxcookiename=0;` in the cookies for the url. It does not replace/update the existing one with the value `=0`.
I also have tried with `=;` and it does not replace it either.
I also tried with `https://server.com/foo/index.html` and `https://server.com/foo`.
Basically if I call cm.getCookie(url);
right after I flush I get the same cookie string as earlier with xxxcookiename=0;
appended and the original xxxcookiename
with the old value. What is the issue here?