Example usage for android.webkit CookieManager removeAllCookies

List of usage examples for android.webkit CookieManager removeAllCookies

Introduction

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

Prototype

public abstract void removeAllCookies(@Nullable ValueCallback<Boolean> callback);

Source Link

Document

Removes all cookies.

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void removeAllCookies() {
    CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(null);
    } else {/* w w  w  .  j  a  va  2 s.c  om*/
        //noinspection deprecation
        cookieManager.removeAllCookie();
    }
}

From source file:Main.java

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

    Looper looper = Looper.myLooper();/*from w w  w  . j  a  v  a 2 s . co  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: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  ww . j ava  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:org.schabi.newpipe.ReCaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recaptcha);

    // Set return to Cancel by default
    setResult(RESULT_CANCELED);/*  w  w  w.  ja  v  a2 s.c o m*/

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setTitle(R.string.reCaptcha_title);
        actionBar.setDisplayShowTitleEnabled(true);
    }

    WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView);

    // Enable Javascript
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);

    ReCaptchaWebViewClient webClient = new ReCaptchaWebViewClient(this);
    myWebView.setWebViewClient(webClient);

    // Cleaning cache, history and cookies from webView
    myWebView.clearCache(true);
    myWebView.clearHistory();
    android.webkit.CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
            @Override
            public void onReceiveValue(Boolean aBoolean) {
            }
        });
    } else {
        cookieManager.removeAllCookie();
    }

    myWebView.loadUrl(YT_URL);
}

From source file:com.microsoft.services.msa.LiveAuthClient.java

/**
 * Logs out the given user./*from  ww w . j  a v a2  s.  c  o  m*/
 *
 * Also, this method clears the previously created {@link LiveConnectSession}.
 * {@link LiveAuthListener#onAuthComplete(LiveStatus, LiveConnectSession, Object)} will be
 * called on completion. Otherwise,
 * {@link LiveAuthListener#onAuthError(LiveAuthException, Object)} will be called.
 *
 * @param userState arbitrary object that is used to determine the caller of the method.
 * @param listener called on either completion or error during the logout process.
 */
public void logout(Object userState, LiveAuthListener listener) {
    if (listener == null) {
        listener = NULL_LISTENER;
    }

    session.setAccessToken(null);
    session.setAuthenticationToken(null);
    session.setRefreshToken(null);
    session.setScopes(null);
    session.setTokenType(null);

    clearRefreshTokenFromPreferences();

    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this.applicationContext);
    CookieManager manager = CookieManager.getInstance();

    // clear cookies to force prompt on login
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        manager.removeAllCookies(null);
    else
        manager.removeAllCookie();

    cookieSyncManager.sync();
    listener.onAuthComplete(LiveStatus.UNKNOWN, null, userState);
}

From source file:com.dish.browser.activity.BrowserActivity.java

@SuppressLint("NewApi")
@SuppressWarnings("deprecation")
public void clearCookies() {
    // TODO Break out web storage deletion into its own option/action
    // TODO clear web storage for all sites that are visited in Incognito mode
    WebStorage storage = WebStorage.getInstance();
    storage.deleteAllData();//from ww w.j a v a  2  s.  com
    CookieManager c = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        c.removeAllCookies(null);
    } else {
        CookieSyncManager.createInstance(this);
        c.removeAllCookie();
    }
}