sync Cookie With System Browser - Android android.webkit

Android examples for android.webkit:CookieManager

Description

sync Cookie With System Browser

Demo Code

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;

public class Main{

    /**/*from  w  ww.  j ava2s  .com*/
     * Sync cookie with system browser.
     *
     * @param context
     *     the context
     */
    public static void syncCookieWithSystemBrowser(Context context) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            CookieManager.getInstance().flush();
        } else {
            CookieSyncManager.createInstance(context);
            CookieSyncManager.getInstance().startSync();
            CookieSyncManager.getInstance().sync();
        }
    }

}

Related Tutorials