Example usage for android.webkit CookieSyncManager sync

List of usage examples for android.webkit CookieSyncManager sync

Introduction

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

Prototype

@Deprecated
public void sync() 

Source Link

Document

sync() forces sync manager to sync now

Usage

From source file:com.suning.mobile.ebuy.lottery.network.util.Caller.java

/**
 * webviewcookie//  w  ww .  j  a v  a  2 s.  c o m
 */
public void syncCookie() {
    List<Cookie> cookies = mClient.getCookieStore().getCookies();
    if (!cookies.isEmpty()) {
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(mApplication);
        CookieManager cookieManager = CookieManager.getInstance();
        for (Cookie cookie : cookies) {
            String domain = cookie.getDomain();
            String strCookies = cookie.getName() + "=" + cookie.getValue() + "; domain=" + domain;
            cookieManager.setCookie(domain, strCookies);
            cookieSyncManager.sync();
        }
    }
}

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  a  v a2s.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();
    }
}

From source file:com.liato.bankdroid.WebViewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);/*from   ww  w  .j  a  v a 2s .  c o  m*/
    this.addTitleButton(R.drawable.title_icon_back, "back", this);
    this.addTitleButton(R.drawable.title_icon_forward, "forward", this);
    this.addTitleButton(R.drawable.title_icon_refresh, "refresh", this);
    this.setTitleButtonEnabled("forward", false);
    this.setTitleButtonEnabled("back", false);
    this.setTitleButtonEnabled("refresh", false);

    final CookieSyncManager csm = CookieSyncManager.createInstance(this);
    mWebView = (WebView) findViewById(R.id.wvBank);
    mWebView.setBackgroundColor(0);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setBuiltInZoomControls(true);
    mWebView.getSettings().setUserAgentString(Urllib.DEFAULT_USER_AGENT);
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

    mWebView.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            activity.setProgressBar(progress);
            if (progress == 100) {
                Handler handler = new Handler();
                Runnable runnable = new Runnable() {
                    public void run() {
                        activity.hideProgressBar();
                    }
                };
                // Let the progress bar hit 100% before we hide it.
                handler.postDelayed(runnable, 100);

            } else if (mFirstPageLoaded) {
                activity.showProgressBar();
            }
        }
    });
    mWebView.setWebViewClient(new BankWebViewClient());
    String preloader = "Error...";
    try {
        preloader = IOUtils.toString(getResources().openRawResource(R.raw.loading));
        preloader = String.format(preloader, "", // Javascript function
                "" // HTML
        );
    } catch (NotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mWebView.loadDataWithBaseURL("what://is/this/i/dont/even", preloader, "text/html", "utf-8", null);

    Bundle extras = getIntent().getExtras();
    final long bankId = extras.getLong("bankid", -1);
    //final long bankId = -1;
    if (bankId >= 0) {
        Runnable generateLoginPage = new Runnable() {
            public void run() {
                Bank bank = BankFactory.bankFromDb(bankId, WebViewActivity.this, false);
                SessionPackage loginPackage = bank.getSessionPackage(WebViewActivity.this);
                CookieStore cookieStore = loginPackage.getCookiestore();
                if ((cookieStore != null) && !cookieStore.getCookies().isEmpty()) {
                    CookieManager cookieManager = CookieManager.getInstance();
                    String cookieString;
                    for (Cookie cookie : cookieStore.getCookies()) {
                        cookieString = String.format("%s=%s;%spath=%s; domain=%s;", cookie.getName(),
                                cookie.getValue(),
                                cookie.getExpiryDate() == null ? ""
                                        : "expires=" + cookie.getExpiryDate() + "; ",
                                cookie.getPath() == null ? "/" : cookie.getPath(), cookie.getDomain());
                        cookieManager.setCookie(cookie.getDomain(), cookieString);
                    }
                    csm.sync();
                }
                mWebView.loadDataWithBaseURL("what://is/this/i/dont/even", loginPackage.getHtml(), "text/html",
                        "utf-8", null);
            }
        };
        new Thread(generateLoginPage).start();
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void addCookie(Cookie c, boolean addToWebViewCookieManager, boolean sync) {
    if (addToWebViewCookieManager) {
        CookieManager mgr;//from ww w . j a v  a2 s  .c om
        CookieSyncManager syncer;
        try {
            syncer = CookieSyncManager.getInstance();
            mgr = getCookieManager();
        } catch (IllegalStateException ex) {
            syncer = CookieSyncManager.createInstance(this.getContext());
            mgr = getCookieManager();
        }
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z");
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        String cookieString = c.getName() + "=" + c.getValue() + "; Domain=" + c.getDomain() + "; Path="
                + c.getPath() + "; " + (c.isSecure() ? "Secure;" : "") + (c.isHttpOnly() ? "httpOnly;" : "")
                + (c.getExpires() != 0 ? ("Expires=" + format.format(new Date(c.getExpires())) + ";") : "");
        mgr.setCookie("http" + (c.isSecure() ? "s" : "") + "://" + c.getDomain() + c.getPath(), cookieString);
        if (sync) {
            syncer.sync();
        }
    }
    super.addCookie(c);

}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void addCookie(Cookie[] cs, boolean addToWebViewCookieManager, boolean sync) {
    if (addToWebViewCookieManager) {
        CookieManager mgr;/*from  w  w w.  j  a va 2  s  .  c o  m*/
        CookieSyncManager syncer;
        try {
            syncer = CookieSyncManager.getInstance();
            mgr = getCookieManager();
        } catch (IllegalStateException ex) {
            syncer = CookieSyncManager.createInstance(this.getContext());
            mgr = getCookieManager();
        }
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z");
        format.setTimeZone(TimeZone.getTimeZone("GMT"));

        for (Cookie c : cs) {
            String cookieString = c.getName() + "=" + c.getValue() + "; Domain=" + c.getDomain() + "; Path="
                    + c.getPath() + "; " + (c.isSecure() ? "Secure;" : "")
                    + (c.getExpires() != 0 ? (" Expires=" + format.format(new Date(c.getExpires())) + ";") : "")
                    + (c.isHttpOnly() ? "httpOnly;" : "");
            mgr.setCookie("http" + (c.isSecure() ? "s" : "") + "://" + c.getDomain() + c.getPath(),
                    cookieString);

        }

        if (sync) {
            syncer.sync();
        }
    }
    super.addCookie(cs);

}