Example usage for android.webkit CookieManager getInstance

List of usage examples for android.webkit CookieManager getInstance

Introduction

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

Prototype

public static CookieManager getInstance() 

Source Link

Document

Gets the singleton CookieManager instance.

Usage

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

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override/*from w w  w .java  2s.  co  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;
}

From source file:net.nym.mutils.ui.test.TestWebViewActivity.java

/**
 * ?cookie//from ww w.  j  a va2  s  . c om
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void synCookies(Context context, String url) {
    // ??URI
    URL uri = null;
    try {
        uri = new URL(url);
    } catch (MalformedURLException e) {
        try {
            // ?
            uri = new URL(MethodNames.HOST_ADDRESS);
        } catch (MalformedURLException e1) {
            return;
        }
    }

    CookieManager cookieManager = CookieManager.getInstance();
    // cookieManager.removeAllCookie();
    cookieManager.setAcceptCookie(true);
    PersistentCookieStore cookieStore = new PersistentCookieStore(this);
    if (null != cookieStore) {
        List<Cookie> cookies = cookieStore.getCookies();
        for (Cookie c : cookies) {
            if (!StringUtils.isNullOrEmpty(c.getName()) && !StringUtils.isNullOrEmpty(c.getValue())) {
                // cookiesHttpClientcookie
                StringBuilder cookie = new StringBuilder(c.getName() + "=" + c.getValue());
                cookieManager.setCookie(uri.getHost(), cookie.toString());//
            }
        }
    }
    if (!ContextUtils.isLollipopOrLater()) {

        CookieSyncManager.getInstance().sync();
    } else {
        cookieManager.flush();
    }

}

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

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override/*from www .ja  va2  s. com*/
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:android.net.http.RequestHandle.java

/**
 * Create and queue a redirect request./*from  w ww  .jav a  2  s .  co m*/
 *
 * @param redirectTo URL to redirect to
 * @param statusCode HTTP status code returned from original request
 * @param cacheHeaders Cache header for redirect URL
 * @return true if setup succeeds, false otherwise (redirect loop
 * count exceeded, body provider unable to rewind on 307 redirect)
 */
public boolean setupRedirect(String redirectTo, int statusCode, Map<String, String> cacheHeaders) {
    if (HttpLog.LOGV) {
        HttpLog.v("RequestHandle.setupRedirect(): redirectCount " + mRedirectCount);
    }

    // be careful and remove authentication headers, if any
    mHeaders.remove(AUTHORIZATION_HEADER);
    mHeaders.remove(PROXY_AUTHORIZATION_HEADER);

    if (++mRedirectCount == MAX_REDIRECT_COUNT) {
        // Way too many redirects -- fail out
        if (HttpLog.LOGV)
            HttpLog.v("RequestHandle.setupRedirect(): too many redirects " + mRequest);
        mRequest.error(EventHandler.ERROR_REDIRECT_LOOP, com.android.internal.R.string.httpErrorRedirectLoop);
        return false;
    }

    if (mUrl.startsWith("https:") && redirectTo.startsWith("http:")) {
        // implement http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3
        if (HttpLog.LOGV) {
            HttpLog.v("blowing away the referer on an https -> http redirect");
        }
        mHeaders.remove("Referer");
    }

    mUrl = redirectTo;
    try {
        mUri = new WebAddress(mUrl);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // update the "Cookie" header based on the redirected url
    mHeaders.remove("Cookie");
    String cookie = CookieManager.getInstance().getCookie(mUri);
    if (cookie != null && cookie.length() > 0) {
        mHeaders.put("Cookie", cookie);
    }

    if ((statusCode == 302 || statusCode == 303) && mMethod.equals("POST")) {
        if (HttpLog.LOGV) {
            HttpLog.v("replacing POST with GET on redirect to " + redirectTo);
        }
        mMethod = "GET";
    }
    /* Only repost content on a 307.  If 307, reset the body
       provider so we can replay the body */
    if (statusCode == 307) {
        try {
            if (mBodyProvider != null)
                mBodyProvider.reset();
        } catch (java.io.IOException ex) {
            if (HttpLog.LOGV) {
                HttpLog.v("setupRedirect() failed to reset body provider");
            }
            return false;
        }

    } else {
        mHeaders.remove("Content-Type");
        mBodyProvider = null;
    }

    // Update the cache headers for this URL
    mHeaders.putAll(cacheHeaders);

    createAndQueueNewRequest();
    return true;
}

From source file:com.microsoft.aad.adal.AuthenticationActivity.java

@SuppressLint("SetJavaScriptEnabled")
@Override//  w w  w.  ja  v a2s.  c o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(
            this.getResources().getIdentifier("activity_authentication", "layout", this.getPackageName()));
    CookieSyncManager.createInstance(getApplicationContext());
    CookieSyncManager.getInstance().sync();
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);

    // Get the message from the intent
    mAuthRequest = getAuthenticationRequestFromIntent(getIntent());
    if (mAuthRequest == null) {
        Log.d(TAG, "Request item is null, so it returns to caller");
        Intent resultIntent = new Intent();
        resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_CODE,
                AuthenticationConstants.Browser.WEBVIEW_INVALID_REQUEST);
        resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_MESSAGE,
                "Intent does not have request details");
        returnToCaller(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, resultIntent);
        return;
    }

    if (mAuthRequest.getAuthority() == null || mAuthRequest.getAuthority().isEmpty()) {
        returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_AUTHORITY);
        return;
    }

    if (mAuthRequest.getResource() == null || mAuthRequest.getResource().isEmpty()) {
        returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_RESOURCE);
        return;
    }

    if (mAuthRequest.getClientId() == null || mAuthRequest.getClientId().isEmpty()) {
        returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_CLIENTID_KEY);
        return;
    }

    if (mAuthRequest.getRedirectUri() == null || mAuthRequest.getRedirectUri().isEmpty()) {
        returnError(ADALError.ARGUMENT_EXCEPTION, AuthenticationConstants.Broker.ACCOUNT_REDIRECT);
        return;
    }

    mRedirectUrl = mAuthRequest.getRedirectUri();
    Logger.v(TAG, "OnCreate redirectUrl:" + mRedirectUrl);
    // Create the Web View to show the page
    mWebView = (WebView) findViewById(
            this.getResources().getIdentifier("webView1", "id", this.getPackageName()));
    Logger.v(TAG, "User agent:" + mWebView.getSettings().getUserAgentString());
    mStartUrl = "about:blank";

    try {
        Oauth2 oauth = new Oauth2(mAuthRequest);
        mStartUrl = oauth.getCodeRequestUrl();
        mQueryParameters = oauth.getAuthorizationEndpointQueryParameters();
    } catch (UnsupportedEncodingException e) {
        Log.d(TAG, e.getMessage());
        Intent resultIntent = new Intent();
        resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_REQUEST_INFO, mAuthRequest);
        returnToCaller(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, resultIntent);
        return;
    }

    // Create the broadcast receiver for cancel
    Logger.v(TAG, "Init broadcastReceiver with requestId:" + mAuthRequest.getRequestId() + " "
            + mAuthRequest.getLogInfo());
    mReceiver = new ActivityBroadcastReceiver();
    mReceiver.mWaitingRequestId = mAuthRequest.getRequestId();
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver,
            new IntentFilter(AuthenticationConstants.Browser.ACTION_CANCEL));

    String userAgent = mWebView.getSettings().getUserAgentString();
    mWebView.getSettings()
            .setUserAgentString(userAgent + AuthenticationConstants.Broker.CLIENT_TLS_NOT_SUPPORTED);
    userAgent = mWebView.getSettings().getUserAgentString();
    Logger.v(TAG, "UserAgent:" + userAgent);

    if (isBrokerRequest(getIntent())) {
        // This activity is started from calling app and running in
        // Authenticator's process
        mCallingPackage = getCallingPackage();
        Logger.i(TAG, "It is a broker request for package:" + mCallingPackage, "");

        if (mCallingPackage == null) {
            Logger.v(TAG, "startActivityForResult is not used to call this activity");
            Intent resultIntent = new Intent();
            resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_CODE,
                    AuthenticationConstants.Browser.WEBVIEW_INVALID_REQUEST);
            resultIntent.putExtra(AuthenticationConstants.Browser.RESPONSE_ERROR_MESSAGE,
                    "startActivityForResult is not used to call this activity");
            returnToCaller(AuthenticationConstants.UIResponse.BROWSER_CODE_ERROR, resultIntent);
            return;
        }

        mAccountAuthenticatorResponse = getIntent()
                .getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
        if (mAccountAuthenticatorResponse != null) {
            mAccountAuthenticatorResponse.onRequestContinued();
        }
        PackageHelper info = new PackageHelper(AuthenticationActivity.this);
        mCallingPackage = getCallingPackage();
        mCallingUID = info.getUIDForPackage(mCallingPackage);
        String signatureDigest = info.getCurrentSignatureForPackage(mCallingPackage);
        mStartUrl = getBrokerStartUrl(mStartUrl, mCallingPackage, signatureDigest);

        if (!isCallerBrokerInstaller()) {
            Logger.v(TAG, "Caller needs to be verified using special redirectUri");
            mRedirectUrl = PackageHelper.getBrokerRedirectUrl(mCallingPackage, signatureDigest);
        }
        Logger.v(TAG,
                "OnCreate redirectUrl:" + mRedirectUrl + " startUrl:" + mStartUrl + " calling package:"
                        + mCallingPackage + " signatureDigest:" + signatureDigest + " current Context Package: "
                        + getPackageName());
    }
    mRegisterReceiver = false;
    final String postUrl = mStartUrl;
    Logger.i(TAG, "OnCreate startUrl:" + mStartUrl + " calling package:" + mCallingPackage, " device:"
            + android.os.Build.VERSION.RELEASE + " " + android.os.Build.MANUFACTURER + android.os.Build.MODEL);

    setupWebView(mRedirectUrl, mQueryParameters, mAuthRequest);

    if (savedInstanceState == null) {
        mWebView.post(new Runnable() {
            @Override
            public void run() {
                // load blank first to avoid error for not loading webview
                mWebView.loadUrl("about:blank");
                mWebView.loadUrl(postUrl);
            }
        });
    } else {
        Logger.v(TAG, "Reuse webview");
    }
}

From source file:org.runbuddy.libtomahawk.resolver.ScriptAccount.java

@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
public ScriptAccount(String path, boolean manuallyInstalled) {
    String prefix = manuallyInstalled ? "file://" : "file:///android_asset";
    mPath = prefix + path;/* w  w  w.  j  a  v a 2s. c o m*/
    mManuallyInstalled = manuallyInstalled;
    String[] parts = mPath.split("/");
    mName = parts[parts.length - 1];
    InputStream inputStream = null;
    try {
        if (mManuallyInstalled) {
            File metadataFile = new File(path + File.separator + "content" + File.separator + "metadata.json");
            inputStream = new FileInputStream(metadataFile);
        } else {
            inputStream = TomahawkApp.getContext().getAssets()
                    .open(path.substring(1) + "/content/metadata.json");
        }
        String metadataString = IOUtils.toString(inputStream, Charsets.UTF_8);
        mMetaData = GsonHelper.get().fromJson(metadataString, ScriptResolverMetaData.class);
        if (mMetaData == null) {
            Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount.");
            return;
        }
    } catch (IOException e) {
        Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage());
        Log.e(TAG, "Couldn't read metadata.json. Cannot instantiate ScriptAccount.");
        return;
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                Log.e(TAG, "ScriptAccount: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
        }
    }

    CookieManager.setAcceptFileSchemeCookies(true);

    mWebView = new WebView(TomahawkApp.getContext());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true);
    }
    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDatabaseEnabled(true);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        //noinspection deprecation
        settings.setDatabasePath(TomahawkApp.getContext().getDir("databases", Context.MODE_PRIVATE).getPath());
    }
    settings.setDomStorageEnabled(true);
    mWebView.setWebChromeClient(new TomahawkWebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            //initalize WebView
            String data = "<!DOCTYPE html>" + "<html>" + "<head><title>" + mName + "</title></head>" + "<body>"
                    + "<script src=\"file:///android_asset/js/rsvp-latest.min.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/cryptojs-core.js"
                    + "\" type=\"text/javascript\"></script>";
            if (mMetaData.manifest.scripts != null) {
                for (String scriptPath : mMetaData.manifest.scripts) {
                    data += "<script src=\"" + mPath + "/content/" + scriptPath
                            + "\" type=\"text/javascript\"></script>";
                }
            }
            try {
                String[] cryptoJsScripts = TomahawkApp.getContext().getAssets().list("js/cryptojs");
                for (String scriptPath : cryptoJsScripts) {
                    data += "<script src=\"file:///android_asset/js/cryptojs/" + scriptPath
                            + "\" type=\"text/javascript\"></script>";
                }
            } catch (IOException e) {
                Log.e(TAG, "ScriptResolver: " + e.getClass() + ": " + e.getLocalizedMessage());
            }
            data += "<script src=\"file:///android_asset/js/tomahawk_android_pre.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk-infosystem.js"
                    + "\" type=\"text/javascript\"></script>"
                    + "<script src=\"file:///android_asset/js/tomahawk_android_post.js"
                    + "\" type=\"text/javascript\"></script>" + "<script src=\"" + mPath + "/content/"
                    + mMetaData.manifest.main + "\" type=\"text/javascript\"></script>" + "</body></html>";
            mWebView.setWebViewClient(new ScriptWebViewClient(ScriptAccount.this));
            mWebView.addJavascriptInterface(new ScriptInterface(ScriptAccount.this), SCRIPT_INTERFACE_NAME);
            mWebView.loadDataWithBaseURL("file:///android_asset/test.html", data, "text/html", null, null);
        }
    });
}

From source file:nya.miku.wishmaster.http.cloudflare.CloudflareChecker.java

private Cookie checkAntiDDOS(final CloudflareException exception, final HttpHost proxy, CancellableTask task,
        final Activity activity) {
    synchronized (lock) {
        if (processing)
            return null;
        processing = true;/*from  w  w w.  j  av a  2  s  . c om*/
    }
    processing2 = true;
    currentCookie = null;

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieSyncManager.createInstance(activity);
        CookieManager.getInstance().removeAllCookie();
    } else {
        CompatibilityImpl.clearCookies(CookieManager.getInstance());
    }

    final ViewGroup layout = (ViewGroup) activity.getWindow().getDecorView().getRootView();
    final WebViewClient client = new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public void onPageFinished(WebView webView, String url) {
            super.onPageFinished(webView, url);
            Logger.d(TAG, "Got Page: " + url);
            String value = null;
            try {
                String[] cookies = CookieManager.getInstance().getCookie(url).split("[;]");
                for (String cookie : cookies) {
                    if ((cookie != null) && (!cookie.trim().equals(""))
                            && (cookie.startsWith(" " + exception.getRequiredCookieName() + "="))) {
                        value = cookie.substring(exception.getRequiredCookieName().length() + 2);
                    }
                }
            } catch (NullPointerException e) {
                Logger.e(TAG, e);
            }
            if (value != null) {
                BasicClientCookieHC4 cf_cookie = new BasicClientCookieHC4(exception.getRequiredCookieName(),
                        value);
                cf_cookie.setDomain("." + Uri.parse(url).getHost());
                cf_cookie.setPath("/");
                currentCookie = cf_cookie;
                Logger.d(TAG, "Cookie found: " + value);
                processing2 = false;
            } else {
                Logger.d(TAG, "Cookie is not found");
            }
        }
    };

    activity.runOnUiThread(new Runnable() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void run() {
            webView = new WebView(activity);
            webView.setVisibility(View.GONE);
            layout.addView(webView);
            webView.setWebViewClient(client);
            webView.getSettings().setUserAgentString(HttpConstants.USER_AGENT_STRING);
            webView.getSettings().setJavaScriptEnabled(true);
            webViewContext = webView.getContext();
            if (proxy != null)
                WebViewProxy.setProxy(webViewContext, proxy.getHostName(), proxy.getPort());
            webView.loadUrl(exception.getCheckUrl());
        }
    });

    long startTime = System.currentTimeMillis();
    while (processing2) {
        long time = System.currentTimeMillis() - startTime;
        if ((task != null && task.isCancelled()) || time > TIMEOUT) {
            processing2 = false;
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            try {
                layout.removeView(webView);
                webView.stopLoading();
                webView.clearCache(true);
                webView.destroy();
                webView = null;
            } finally {
                if (proxy != null)
                    WebViewProxy.setProxy(webViewContext, null, 0);
                processing = false;
            }
        }
    });

    return currentCookie;
}

From source file:org.kotemaru.android.sample.webview.XMLHttpRequestXS.java

private void doRequest(String body) throws Throwable {
    try {//from  w w  w.  j  a  v  a2s .  c o  m
        if (POST.equals(_request.getMethod())) {
            HttpPost httpPost = (HttpPost) _request;
            Header header = httpPost.getFirstHeader(CONTENT_TYPE);
            String ctype = header != null ? header.getValue() : "plain/text; charset=" + HTTP.UTF_8;
            httpPost.setEntity(new StringEntity(body, ctype));
        }
        _response = _client.execute(_request);
        _responseCode = _response.getStatusLine().getStatusCode();

        CookieManager cookieManager = CookieManager.getInstance();
        Header[] cookies = _response.getHeaders("Set-Cookie");
        for (int i = 0; i < cookies.length; i++) {
            cookieManager.setCookie(_request.getURI().toString(), cookies[i].getValue());
        }

        if (Log.isLoggable(TAG, Log.DEBUG))
            debugLog();
    } catch (Throwable t) {
        Log.e(TAG, t.getMessage(), t);
        _request.abort();
        throw t;
    }
}

From source file:com.github.dfa.diaspora_android.activity.PodSelectionActivity.java

public void onPodSelectionConfirmed(String selectedPod) {
    app.getSettings().setPodDomain(selectedPod);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        try {/*from   w w  w .  jav a  2  s .c o m*/
            CookieManager.getInstance().removeAllCookies(null);
            CookieManager.getInstance().removeSessionCookies(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        try {
            CookieManager.getInstance().removeAllCookie();
            CookieManager.getInstance().removeSessionCookie();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Helpers.animateToActivity(this, MainActivity.class, true);
}