Example usage for android.webkit CookieSyncManager getInstance

List of usage examples for android.webkit CookieSyncManager getInstance

Introduction

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

Prototype

public static CookieSyncManager getInstance() 

Source Link

Document

Singleton access to a CookieSyncManager .

Usage

From source file:in.shick.diode.threads.ThreadsListActivity.java

@Override
protected void onResume() {
    super.onResume();

    int previousTheme = mSettings.getTheme();

    mSettings.loadRedditPreferences(getApplicationContext());

    if (mSettings.getTheme() != previousTheme) {
        relaunchActivity();//from  w w  w.j a v  a 2 s. c  o  m
    } else {
        CookieSyncManager.getInstance().startSync();
        setRequestedOrientation(mSettings.getRotation());

        updateNextPreviousButtons();

        if (mThreadsAdapter != null)
            jumpToThread();

        if (mSettings.isLoggedIn())
            new PeekEnvelopeTask(this, mClient, mSettings.getMailNotificationStyle()).execute();
    }
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
protected void onPause() {
    super.onPause();
    CookieSyncManager.getInstance().stopSync();
    mSettings.saveRedditPreferences(this);
}

From source file:ms.android.facebookSDK.Facebook.java

/**
 * Internal method to handle dialog-based authentication backend for
 * authorize().//ww  w.j  av  a 2  s . c  o  m
 * 
 * @param activity
 *            The Android Activity that will parent the auth dialog.
 * @param applicationId
 *            The Facebook application identifier.
 * @param permissions
 *            A list of permissions required for this application. If you do
 *            not require any permissions, pass an empty String array.
 */
private void startDialogAuth(final Activity activity, String[] permissions) {
    Bundle params = new Bundle();
    if (permissions.length > 0) {
        params.putString("scope", TextUtils.join(",", permissions));
    }
    CookieSyncManager.createInstance(activity);
    dialog(activity, LOGIN, params, new DialogListener() {

        public void onComplete(Bundle values) {
            // ensure any cookies set by the dialog are saved
            CookieSyncManager.getInstance().sync();
            setAccessToken(values.getString(TOKEN));
            setAccessExpiresIn(values.getString(EXPIRES));
            if (isSessionValid()) {
                Util.logd("Facebook-authorize",
                        "Login Success! access_token=" + getAccessToken() + " expires=" + getAccessExpires());
                mAuthDialogListener.onComplete(values);

                try {
                    String jsonUser = request("me");
                    /*   JSONObject obj = null;
                       try {
                          obj = Util.parseJson(jsonUser);
                       } catch (FacebookError e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                       }
                       */

                } catch (Exception e) {
                    e.printStackTrace();
                }

            } else {
                mAuthDialogListener.onFacebookError(new FacebookError("Failed to receive access token."));
            }
        }

        public void onError(DialogError error) {
            Util.logd("Facebook-authorize", "Login failed: " + error);
            mAuthDialogListener.onError(error);
        }

        public void onFacebookError(FacebookError error) {
            Util.logd("Facebook-authorize", "Login failed: " + error);
            mAuthDialogListener.onFacebookError(error);
        }

        public void onCancel() {
            Util.logd("Facebook-authorize", "Login canceled");
            mAuthDialogListener.onCancel();
        }
    });
}

From source file:in.shick.diode.threads.ThreadsListActivity.java

@Override
protected void onPause() {
    super.onPause();
    CookieSyncManager.getInstance().stopSync();
    mSettings.saveRedditPreferences(getApplicationContext());
}

From source file:com.pindroid.fragment.ViewBookmarkFragment.java

private void showInWebView(String url) {
    String readingBackground = SettingsHelper.getReadingBackground(getActivity());
    String readingFont = SettingsHelper.getReadingFont(getActivity());
    String readingFontSize = SettingsHelper.getReadingFontSize(getActivity());
    String readingMargins = SettingsHelper.getReadingMargins(getActivity());

    mWebContent.loadUrl("about:blank");
    mWebContent.clearCache(true);//from   w  w  w  .ja  v  a  2  s .co  m

    CookieManager cookieManager = CookieManager.getInstance();
    CookieSyncManager.createInstance(getActivity());

    cookieManager.setAcceptCookie(true);
    cookieManager.setCookie("http://www.instapaper.com",
            "iptcolor=" + readingBackground + "; expires=Sat, 25-Mar-2023 00:00:00 GMT;path=/;");
    cookieManager.setCookie("http://www.instapaper.com",
            "iptfont=" + readingFont + "; expires=Sat, 25-Mar-2023 00:00:00 GMT;path=/;");
    cookieManager.setCookie("http://www.instapaper.com",
            "iptsize=" + readingFontSize + "; expires=Sat, 25-Mar-2023 00:00:00 GMT;path=/;");
    cookieManager.setCookie("http://www.instapaper.com",
            "iptwidth=" + readingMargins + "; expires=Sat, 25-Mar-2023 00:00:00 GMT;path=/;");

    CookieSyncManager.getInstance().sync();

    mWebContent.setWebViewClient(new WebViewClient() {
    });

    mWebContent.loadUrl(url);
}

From source file:cm.aptoide.com.facebook.android.Facebook.java

/**
 * Internal method to handle dialog-based authentication backend for
 * authorize()./*from w  ww .  ja va2s.  co m*/
 *
 * @param activity
 *            The Android Activity that will parent the auth dialog.
 * @param applicationId
 *            The Facebook application identifier.
 * @param permissions
 *            A list of permissions required for this application. If you do
 *            not require any permissions, pass an empty String array.
 */
private void startDialogAuth(Activity activity, String[] permissions) {
    Bundle params = new Bundle();
    if (permissions.length > 0) {
        params.putString("scope", TextUtils.join(",", permissions));
    }
    CookieSyncManager.createInstance(activity);
    dialog(activity, LOGIN, params, new DialogListener() {

        public void onComplete(Bundle values) {
            // ensure any cookies set by the dialog are saved
            CookieSyncManager.getInstance().sync();
            setAccessToken(values.getString(TOKEN));
            setAccessExpiresIn(values.getString(EXPIRES));
            if (isSessionValid()) {
                Util.logd("Facebook-authorize",
                        "Login Success! access_token=" + getAccessToken() + " expires=" + getAccessExpires());
                mAuthDialogListener.onComplete(values);
            } else {
                mAuthDialogListener.onFacebookError(new FacebookError("Failed to receive access token."));
            }
        }

        public void onError(DialogError error) {
            Util.logd("Facebook-authorize", "Login failed: " + error);
            mAuthDialogListener.onError(error);
        }

        public void onFacebookError(FacebookError error) {
            Util.logd("Facebook-authorize", "Login failed: " + error);
            mAuthDialogListener.onFacebookError(error);
        }

        public void onCancel() {
            Util.logd("Facebook-authorize", "Login canceled");
            mAuthDialogListener.onCancel();
        }
    });
}

From source file:com.microsoft.aad.adal.testapp.MainActivity.java

private void removeCookies() {
    // Clear browser cookies
    CookieSyncManager.createInstance(MainActivity.this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();//from   ww  w .ja v a2s  . com
    CookieSyncManager.getInstance().sync();
}

From source file:com.nbplus.hybrid.BasicWebViewClient.java

@Override
public void onPageFinished(WebView view, String url) {
    Log.d(TAG, "WebView client onPageFinished = " + url);
    super.onPageFinished(view, url);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieSyncManager.getInstance().sync();
    }/*from  w  w w.j  a  v  a2  s.c o m*/
    dismissProgressDialog();
    mPageLoadSuccess = true;
}

From source file:ti.modules.titanium.network.NetworkModule.java

/**
 * Adds a cookie to the system cookie store. Any existing cookie with the same domain, path and name will be replaced with
 * the new cookie. The cookie being set must not have expired, otherwise it will be ignored.
 * @param cookieProxy the cookie to add/*  www  .j a  v  a  2s .co  m*/
 */
@Kroll.method
public void addSystemCookie(CookieProxy cookieProxy) {
    BasicClientCookie cookie = cookieProxy.getHTTPCookie();
    String cookieString = cookie.getName() + "=" + cookie.getValue();
    String domain = cookie.getDomain();
    if (domain == null) {
        Log.w(TAG, "Unable to add system cookie. Need to provide domain.");
        return;
    }
    cookieString += "; domain=" + domain;

    String path = cookie.getPath();
    Date expiryDate = cookie.getExpiryDate();
    boolean secure = cookie.isSecure();
    boolean httponly = TiConvert.toBoolean(cookieProxy.getProperty(TiC.PROPERTY_HTTP_ONLY), false);
    if (path != null) {
        cookieString += "; path=" + path;
    }
    if (expiryDate != null) {
        cookieString += "; expires=" + CookieProxy.systemExpiryDateFormatter.format(expiryDate);
    }
    if (secure) {
        cookieString += "; secure";
    }
    if (httponly) {
        cookieString += " httponly";
    }
    CookieSyncManager.createInstance(TiApplication.getInstance().getRootOrCurrentActivity());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setCookie(domain, cookieString);
    CookieSyncManager.getInstance().sync();
}