java - 在 web View 中删除特定域的所有 cookie

标签 java android android-webview

我正在尝试从某个域中删除所有 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/

相关文章:

java - Mockito 无效使用 Matchers 异常

java - 在命令行上选择测试类别

javascript - 在 react-native-gl-model-view 中使用多个 3d 对象时应用程序崩溃

android - 在 HTML 按钮上打开 Android Activity 在 WebView 中单击

android - 从 WebView 加载 Activity - 第一次安装应用程序但之后就不行了?

Java boolean 方法需要额外的 return 语句吗?

java - 如何将数据预填充到表中?

android - 一旦我的应用程序进程被终止,什么会保持我的 Activity 状态?

javascript - Padding-right 无效,请帮忙?

java - 如何使用canvas绘制运行时图以延迟在android中绘制背景