Clears the cookies in the given cookie handler. - Android Network

Android examples for Network:Cookie

Description

Clears the cookies in the given cookie handler.

Demo Code


//package com.java2s;

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookieStore;

public class Main {
    /**/*from w ww  .j  a  v a 2s.co m*/
     * Clears the cookies in the given cookie handler. Cookies can only be cleared if the
     * cookieHandler is a CookieManager with a non-null CookieStore.
     *
     * @param cookieHandler the cookie handler where cookies should be cleared
     * @return true if cookies were cleared; false otherwise
     */
    public static boolean clearCookies(CookieHandler cookieHandler) {
        if (cookieHandler instanceof CookieManager) {
            CookieManager cookieManager = (CookieManager) cookieHandler;
            CookieStore cookieStore = cookieManager.getCookieStore();
            if (cookieStore != null) {
                cookieStore.removeAll();
                return true;
            }
        }
        return false;
    }
}

Related Tutorials