callback)" I am new to java and trying to delete a WebView cookie using the ...">

How to use "CookieManager :: removeAllCookies (ValueCallback <Boolean> callback)"

I am new to java and trying to delete a WebView cookie using the CookieManager :: removeAllCookies method (ValueCallback callback) . It is not possible to determine what values ​​should be passed to the removeAllCookie method.

The docs https://developer.android.com/reference/android/webkit/ValueCallback.html and https://developer.android.com/reference/android/webkit/CookieManager.html#getInstance%28%29 says nothing about how to use it.

My understanding is ValueCallback is similar to C ++ templates. But it was not possible to get why the object must be passed to delete cookies.

+6
source share
2 answers

From the documentation:

If ValueCallback is provided, onReceiveValue () will be called in the current Looper stream after the operation completes. The value provided to the callback indicates whether cookies have been deleted. You can pass null as a callback if you don't need to know when the operation completed or cookies were deleted.

So you can do it

CookieManager.getInstance().removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { Log.d(TAG, "onReceiveValue " + value); } }); 

or

 CookieManager.getInstance().removeAllCookies(null); 

This method is introduced at API level 21. You may have to say something if you support older versions.

 if(API Level >= 21){ CookieManager.getInstance().removeAllCookies(null); }else{ CookieManager.getInstance().removeAllCookie(); } 
+13
source

You need to call it in the stream.

 private class RemoveCookiesThread extends Thread { private final ValueCallback<Boolean> mCallback; public RemoveCookiesThread(ValueCallback<Boolean> callback) { mCallback = callback; } public void run() { Looper.prepare(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().removeAllCookies(mCallback); } else { CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mApplication); cookieSyncManager.startSync(); CookieManager.getInstance().removeAllCookie(); cookieSyncManager.stopSync(); mCallback.onReceiveValue(true); } Looper.loop(); } } 

And then run the stream:

 RemoveCookiesThread thread = new RemoveCookiesThread(callback); thread.start(); 
0
source

Source: https://habr.com/ru/post/982066/


All Articles