Example usage for android.webkit CookieManager flush

List of usage examples for android.webkit CookieManager flush

Introduction

In this page you can find the example usage for android.webkit CookieManager flush.

Prototype

public abstract void flush();

Source Link

Document

Ensures all cookies currently accessible through the getCookie API are written to persistent storage.

Usage

From source file:de.baumann.browser.helper.helper_webView.java

public static void closeWebView(Activity from, WebView webView) {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(from);
    if (sharedPref.getBoolean("clearCookies", false)) {
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookies(null);
        cookieManager.flush();
    }/* w  w  w .  j  a  v  a 2  s  .  c o m*/

    if (sharedPref.getBoolean("clearCache", false)) {
        webView.clearCache(true);
    }

    if (sharedPref.getBoolean("clearForm", false)) {
        webView.clearFormData();
    }

    if (sharedPref.getBoolean("history", false)) {
        from.deleteDatabase("history.db");
        webView.clearHistory();
    }
    helper_main.isClosed(from);
    sharedPref.edit().putString("started", "").apply();
    from.finishAffinity();
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static void removeAllCookiesV21() {
    final CookieManager cookieManager = CookieManager.getInstance();

    Looper looper = Looper.myLooper();// w w w.  j a  v a 2s  . c  o  m
    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();
        }
    }
}

From source file:net.nym.mutils.ui.test.TestWebViewActivity.java

/**
 * ?cookie//www.j  av a  2s. c o  m
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void synCookies(Context context, String url) {
    // ??URI
    URL uri = null;
    try {
        uri = new URL(url);
    } catch (MalformedURLException e) {
        try {
            // ?
            uri = new URL(MethodNames.HOST_ADDRESS);
        } catch (MalformedURLException e1) {
            return;
        }
    }

    CookieManager cookieManager = CookieManager.getInstance();
    // cookieManager.removeAllCookie();
    cookieManager.setAcceptCookie(true);
    PersistentCookieStore cookieStore = new PersistentCookieStore(this);
    if (null != cookieStore) {
        List<Cookie> cookies = cookieStore.getCookies();
        for (Cookie c : cookies) {
            if (!StringUtils.isNullOrEmpty(c.getName()) && !StringUtils.isNullOrEmpty(c.getValue())) {
                // cookiesHttpClientcookie
                StringBuilder cookie = new StringBuilder(c.getName() + "=" + c.getValue());
                cookieManager.setCookie(uri.getHost(), cookie.toString());//
            }
        }
    }
    if (!ContextUtils.isLollipopOrLater()) {

        CookieSyncManager.getInstance().sync();
    } else {
        cookieManager.flush();
    }

}