Example usage for android.webkit CookieManager removeAllCookie

List of usage examples for android.webkit CookieManager removeAllCookie

Introduction

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

Prototype

@Deprecated
public abstract void removeAllCookie();

Source Link

Document

Removes all cookies.

Usage

From source file:com.easy.facebook.android.facebook.FBLoginManager.java

public void logout(Facebook facebook) throws EasyFacebookError {
    SharedPreferences preferences = this.getActivity().getSharedPreferences(appID, 0);
    android.content.SharedPreferences.Editor editor = preferences.edit();
    editor.putString("accessToken", "");
    editor.putString("uid", "");
    editor.clear();//from w  ww.j a  va2s . c  o  m
    editor.commit();

    CookieSyncManager.createInstance(activity);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    Bundle params = new Bundle();
    params.putString("format", "json");
    params.putString("access_token", facebook.getAccessToken());
    params.putString("method", "auth.expireSession");
    String jsonResponse = "";

    try {
        jsonResponse = Util.openUrl("https://api.facebook.com/restserver.php", "GET", params);

        if (!jsonResponse.equals("true")) {

            JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse);

            if (!objectJSONErrorCheck.isNull("error_msg")) {
                throw new EasyFacebookError(jsonResponse);

            }
        }
    } catch (MalformedURLException e) {

        throw new EasyFacebookError(e.toString(), "MalformedURLException");
    } catch (IOException e) {

        throw new EasyFacebookError(e.toString(), "IOException");
    } catch (JSONException e) {

        throw new EasyFacebookError(e.toString(), "JSONException");
    }

    ((LoginListener) activity).logoutSuccess();

}

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 {//  w  ww  .  j  av  a 2s . c o m
        CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getActivity());
        cookieSyncManager.startSync();
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.removeAllCookie();
        cookieManager.removeSessionCookie();
        cookieSyncManager.stopSync();
        cookieSyncManager.sync();
    }
}

From source file:com.example.office365sample.MainActivity.java

public void clearCookies() {
    CookieSyncManager.createInstance(getApplicationContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    CookieSyncManager.getInstance().sync();
}

From source file:com.msdpe.authenticationdemo.AuthService.java

/**
 * Handles logging the user out including:
 * -deleting cookies so their login with a provider won't be cached in the web view
 * -removing the userdata from the shared preferences
 * -setting the current user object on the client to logged out
 * -optionally redirects to the login page if requested
 * @param shouldRedirectToLogin//from   w w w. j  a  v  a2s .  com
 */
public void logout(boolean shouldRedirectToLogin) {
    //Clear the cookies so they won't auto login to a provider again
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    //Clear the user id and token from the shared preferences
    SharedPreferences settings = mContext.getSharedPreferences("UserData", 0);
    SharedPreferences.Editor preferencesEditor = settings.edit();
    preferencesEditor.clear();
    preferencesEditor.commit();
    //Clear the user and return to the auth activity
    mClient.logout();
    //Take the user back to the auth activity to relogin if requested
    if (shouldRedirectToLogin) {
        Intent logoutIntent = new Intent(mContext, AuthenticationActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:com.wellsandwhistles.android.redditsp.fragments.WebViewFragment.java

@Override
public void onDestroyView() {

    webView.stopLoading();// w w w. jav  a2s . c o  m
    webView.loadData("<html></html>", "text/plain", "UTF-8");
    webView.reload();
    webView.loadUrl("about:blank");
    outer.removeAllViews();
    webView.destroy();

    final CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    super.onDestroyView();
}

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

public void onClickClearCookies(View view) {
    CookieSyncManager.createInstance(MainActivity.this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    CookieSyncManager.getInstance().sync();
}

From source file:com.drisoftie.cwdroid.frag.FragBoard.java

/**
 * Most actions are created here./*from w  ww.  ja  v  a  2  s  .  c o  m*/
 */
@SuppressWarnings("unchecked")
private void initActions() {
    actionInit = new ActionBuilder().with().reg(IGenericAction.class, RegActionMethod.NONE)
            .pack(new AndroidAction<View, Void, Void, Void, Void>(null, null) {
                @Override
                public Object onActionPrepare(String methodName, Object[] methodArgs, Void tag1, Void tag2,
                        Object[] additionalTags) {
                    webBoard.loadUrl(getArguments().getString(FragBoard.class.getName()));

                    webBoard.getSettings().setUseWideViewPort(false);
                    webBoard.getSettings().setJavaScriptEnabled(true);

                    CookieManager cm = CookieManager.getInstance();
                    if (!CwApp.domain().isUserLoggedIn()) {
                        cm.removeAllCookie();
                    } else {
                        CwUser user = CwApp.domain().getLoggedInUser();
                        String cookie = cm.getCookie(getString(R.string.api_domain));
                        if (StringUtils.contains(cookie, getString(R.string.cw_cookie_userid))
                                && StringUtils.contains(cookie,
                                        getString(R.string.cw_cookie_userid) + "=" + user.getId())
                                && cookie.contains(getString(R.string.cw_cookie_pw) + "=" + CredentialUtils
                                        .deobfuscateFromBase64(user.getKeyData(), user.getPwHash()))) {
                        } else {
                            cm.removeAllCookie();
                            cm.setCookie(getString(R.string.api_domain),
                                    getString(R.string.cw_cookie_userid) + "=" + user.getId());
                            cm.setCookie(getString(R.string.api_domain),
                                    getString(R.string.cw_cookie_pw) + "=" + CredentialUtils
                                            .deobfuscateFromBase64(user.getKeyData(), user.getPwHash()));
                        }
                    }
                    skipWorkThreadOnce();
                    return null;
                }

                @Override
                public Void onActionDoWork(String methodName, Object[] methodArgs, Void tag1, Void tag2,
                        Object[] additionalTags) {
                    return null;
                }

                @Override
                public void onActionAfterWork(String methodName, Object[] methodArgs, Void result, Void tag1,
                        Void tag2, Object[] additionalTags) {
                }
            });

    actionRefresh = new ActionBuilder().with(swipeBoard)
            .reg(SwipeRefreshLayout.OnRefreshListener.class, "setOnRefreshListener")
            .reg(IGenericAction.class, RegActionMethod.NONE)
            .pack(new AndroidAction<View, Void, Void, Void, Void>(null, null) {
                @Override
                public Object onActionPrepare(String methodName, Object[] methodArgs, Void tag1, Void tag2,
                        Object[] additionalTags) {
                    webBoard.loadUrl(getArguments().getString(FragShoutbox.class.getName()));
                    skipWorkThreadOnce();
                    return null;
                }

                @Override
                public Void onActionDoWork(String methodName, Object[] methodArgs, Void tag1, Void tag2,
                        Object[] additionalTags) {
                    return null;
                }

                @Override
                public void onActionAfterWork(String methodName, Object[] methodArgs, Void result, Void tag1,
                        Void tag2, Object[] additionalTags) {
                }
            });
}

From source file:com.cerema.cloud2.ui.dialog.SamlWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override//  w ww . j  ava 2s. c om
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);

    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout

    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);

        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(MainApp.getUserAgent());
        webSettings.setSaveFormData(false);

        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();

        mSsoWebView.loadUrl(mInitialUrl);
    }

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();

    return ssoRootView;
}

From source file:com.example.sabeeh.helloworld.AuthService.java

/**
 * Handles logging the user out including:
 * -deleting cookies so their login with a provider won't be cached in the web view
 * -removing the userdata from the shared preferences
 * -setting the current user object on the client to logged out
 * -optionally redirects to the login page if requested
 * @param shouldRedirectToLogin// w  w  w  . j  a v a  2 s. c  om
 */
public void logout(boolean shouldRedirectToLogin) {
    //Clear the cookies so they won't auto login to a provider again
    CookieSyncManager.createInstance(mContext);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
    //Clear the user id and token from the shared preferences
    ClearcacheUserToken();
    //Clear the user and return to the auth activity
    mClient.logout();
    //Take the user back to the auth activity to relogin if requested
    if (shouldRedirectToLogin) {
        Intent logoutIntent = new Intent(mContext, LoginActivity.class);
        logoutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(logoutIntent);
    }
}

From source file:com.digitalarx.android.ui.dialog.SamlWebViewDialog.java

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override// w ww  . j  a va 2 s. c o  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);

    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, false); // null parent view because it will go in the dialog layout

    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getSherlockActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);

        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();
        mSsoWebView.loadUrl(mInitialUrl);

        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(OwnCloudClient.USER_AGENT);
        webSettings.setSaveFormData(false);
    }

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();

    return ssoRootView;
}