我是
java的新手并尝试使用CookieManager :: removeAllCookies(ValueCallback回调)方法删除WebView cookie.无法确定必须将哪些值传递给removeAllCookie方法.
文档https://developer.android.com/reference/android/webkit/ValueCallback.html和https://developer.android.com/reference/android/webkit/CookieManager.html#getInstance%28%29没有说明如何使用它.
我的理解是ValueCallback类似于c模板.但无法理解为什么需要传递一个对象来删除cookie.
解决方法
从文档:
If a ValueCallback is provided,onReceiveValue() will be called on the current thread’s Looper once the operation is complete. The value provided to the callback indicates whether any cookies were removed. You can pass null as the callback if you don’t need to know when the operation completes or whether any cookies were removed
所以你可以做到这一点
CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { Log.d(TAG,"onReceiveValue " + value); } });
要么
CookieManager.getInstance().removeAllCookies(null);
此方法在API级别21中引入.如果您支持旧版本,则可能必须提供类似的内容.
if(API Level >= 21){ CookieManager.getInstance().removeAllCookies(null); }else{ CookieManager.getInstance().removeAllCookie(); }