Example usage for android.webkit CookieSyncManager startSync

List of usage examples for android.webkit CookieSyncManager startSync

Introduction

In this page you can find the example usage for android.webkit CookieSyncManager startSync.

Prototype

@Deprecated
public void startSync() 

Source Link

Document

startSync() requests sync manager to start sync.

Usage

From source file:Main.java

@SuppressWarnings("deprecation")
public static void clearCookies(Context context) {

    if (Build.VERSION.SDK_INT >= 21) {
        try {/*from  ww  w  . j  a va 2s  .co  m*/
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } catch (Exception e) {
        }
    } else {
        try {
            CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
            cookieSyncMngr.startSync();
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        } catch (Exception e) {
        }
    }
}

From source file:org.catrobat.catroid.ui.WebViewActivity.java

@SuppressWarnings("deprecated")
@SuppressLint("NewApi")
public static void clearCookies(Context context) {
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
        cookieSyncMngr.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncMngr.stopSync();//from  w ww .  j av a2s .c  om
        cookieSyncMngr.sync();
    } else {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    }
}

From source file:org.dmfs.oauth2.android.fragment.InteractiveGrantFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Nullable//www .  j  a v a2  s  .co m
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    if (mWebView == null) {
        // create and configure the WebView
        // Note using just getActivity would will leak the activity.
        mWebView = new WebView(getActivity().getApplicationContext());
        mWebView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setOnKeyListener(this);
        mWebView.setWebViewClient(mGrantWebViewClient);
        mWebView.loadUrl(mGrant.authorizationUrl().toASCIIString());

        // wipe cookies to enforce a new login
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().flush();
        } else {
            CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getActivity());
            cookieSyncMngr.startSync();
            CookieManager cookieManager = CookieManager.getInstance();
            cookieManager.removeAllCookie();
            cookieManager.removeSessionCookie();
            cookieSyncMngr.stopSync();
            cookieSyncMngr.sync();
        }
    }
    return mWebView;
}

From source file:com.popdeem.sdk.uikit.fragment.PDUIInstagramLoginFragment.java

@SuppressWarnings("deprecation")
private void clearCookies() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {/*ww w .j  av  a2 s .co  m*/
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getActivity());
        cookieSyncManager.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
        cookieSyncManager.sync();
    }
}

From source file:com.polyvi.xface.extension.xmlhttprequest.XXMLHttpRequest.java

/**
 * cookie//from w w  w  . j  av a 2s.  com
 * 
 * @param url
 *            url?
 */
private void addCookie(String url) {
    // cookie?
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mContext);
    cookieSyncManager.startSync();
    String cookie = CookieManager.getInstance().getCookie(url);
    if (cookie != null) {
        mRequestHeaders.put("Cookie", cookie);
    }
}

From source file:com.polyvi.xface.extension.filetransfer.XFileTransferExt.java

/**
 * connectionCookie//from  w  w w  .  j av  a 2s .co  m
 * @param connection   Http
 * @param propert       cookie?
 */
private void setCookieProperty(HttpURLConnection connection, String propert) {
    //Add cookie support
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getContext());
    cookieSyncManager.startSync();
    String cookie = CookieManager.getInstance().getCookie(propert);
    if (cookie != null) {
        connection.setRequestProperty("cookie", cookie);
    }
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

@Override
public void onAccountLogoutSuccess() {
    LOG.debug("onAccountLogoutSuccess");
    this.onAccountIsNotLoggedIn();

    this.annotationsManager = null;

    //if current account ??
    final SimplifiedCatalogAppServicesType app = Simplified.getCatalogAppServices();
    app.getBooks().destroyBookStatusCache();

    Simplified.getCatalogAppServices().reloadCatalog(true, this.account);
    final Resources rr = NullCheck.notNull(this.getResources());
    final Context context = this.getApplicationContext();
    final CharSequence text = NullCheck.notNull(rr.getString(R.string.settings_logout_succeeded));
    final int duration = Toast.LENGTH_SHORT;

    final TextView bt = NullCheck.notNull(this.barcode_text);
    final TextView pt = NullCheck.notNull(this.pin_text);

    UIThread.runOnUIThread(() -> {//from   w w w  .j  ava 2 s  .c o m
        bt.setVisibility(View.GONE);
        pt.setVisibility(View.GONE);

        final Toast toast = Toast.makeText(context, text, duration);
        toast.show();
        finish();
        overridePendingTransition(0, 0);
        startActivity(getIntent());
        overridePendingTransition(0, 0);
    });

    // logout clever

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

        CookieManager.getInstance().removeAllCookies(null);
        CookieManager.getInstance().flush();
    } else {
        final CookieSyncManager cookie_sync_manager = CookieSyncManager.createInstance(this);
        cookie_sync_manager.startSync();
        final CookieManager cookie_manager = CookieManager.getInstance();
        cookie_manager.removeAllCookie();
        cookie_manager.removeSessionCookie();
        cookie_sync_manager.stopSync();
        cookie_sync_manager.sync();
    }
}