callback)"-6ren"> callback)"-我是 java 的新手,正在尝试使用 CookieManager::removeAllCookies(ValueCallback callback) 方法删除 WebView cookie。无法确定必-6ren">
gpt4 book ai didi

android - 如何使用 "CookieManager::removeAllCookies(ValueCallback callback)"

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:09 26 4
gpt4 key购买 nike

我是 java 的新手,正在尝试使用 CookieManager::removeAllCookies(ValueCallback callback) 方法删除 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();
}

关于android - 如何使用 "CookieManager::removeAllCookies(ValueCallback<Boolean> callback)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28352463/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com