android – 如何使用“CookieManager :: removeAllCookies(ValueCallback callback)”

前端之家收集整理的这篇文章主要介绍了android – 如何使用“CookieManager :: removeAllCookies(ValueCallback callback)”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是 java的新手并尝试使用CookieManager :: removeAllCookies(ValueCallback回调)方法删除WebView cookie.无法确定必须将哪些值传递给removeAllCookie方法.

文档https://developer.android.com/reference/android/webkit/ValueCallback.htmlhttps://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();
}
原文链接:https://www.f2er.com/android/317030.html

猜你在找的Android相关文章