Java tutorial
//package com.java2s; import android.annotation.TargetApi; import android.content.Context; import android.os.Build; import android.os.Looper; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.ValueCallback; public class Main { @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static void removeAllCookiesV21() { final CookieManager cookieManager = CookieManager.getInstance(); Looper looper = Looper.myLooper(); boolean prepared = false; if (looper == null) { Looper.prepare(); prepared = true; } // requires a looper cookieManager.removeAllCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { Thread thread = new Thread() { @Override public void run() { // is synchronous, run in background cookieManager.flush(); } }; thread.start(); } }); if (prepared) { looper = Looper.myLooper(); if (looper != null) { looper.quit(); } } } /** * Removes all cookies for this application. */ public static void removeAllCookies(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { removeAllCookiesV21(); } else { removeAllCookiesV14(context.getApplicationContext()); } } @SuppressWarnings("deprecation") private static void removeAllCookiesV14(Context context) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); } }