我正在尝试从某个域中删除所有 cookie,有没有办法做到这一点?
我看到的唯一方法是 removeAllCookies。
谢谢。
最佳答案
根据 documentation ,我们没有删除单个 cookie 的方法。
但是我们可以使用 setCookie()
来清除站点的 cookie。作为,
public abstract void setCookie (String url, String value)
Sets a cookie for the given URL. Any existing cookie with the same host, path and name will be replaced with the new cookie. The cookie being set will be ignored if it is expired.
因此,解决方案是,如 this 中所述回答,我们需要为每个主机 key 手动清理每个cookie。例如:- facebook
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "locale=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "datr=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "s=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "csm=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "fr=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "lu=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "c_user=");
android.webkit.CookieManager.getInstance().setCookie(".facebook.com", "xs=");
关于java - 在 web View 中删除特定域的所有 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35390590/