List of usage examples for android.webkit CookieManager getInstance
public static CookieManager getInstance()
From source file:com.msopentech.applicationgateway.EnterpriseBrowserActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { try {/* w w w . jav a 2s .c o m*/ super.onActivityResult(requestCode, resultCode, data); // The data argument can be null if the user simply exited the // activity by clicking back or cancel. if (data == null) { return; } Bundle extras = data.getExtras(); if (extras == null) { return; } switch (requestCode) { case ACTIVITY_SIGN_IN: { if (resultCode != RESULT_CANCELED) { mCustomTabHost.clearAllHistory(); mTraits = (ConnectionTraits) data .getSerializableExtra(EnterpriseBrowserActivity.EXTRAS_TRAITS_KEY); if (mTraits.sessionID == null && mTraits.token == null && mTraits.agent.getAgentId() == null) { // Authentication failed. Have to make user make another attempt while informing of error reason. showSignIn(null, true); } else { mStatusButtonView.setImageResource(R.drawable.connection_green); if (mIsSigninRequired) { mIsSigninRequired = false; } // Switch to agent specific stored data. PersistenceManager.initialize(mTraits.agent.getAgentId()); } } else { if (mTraits == null || mTraits.isError()) { // Will get here if error was received on signIn screen and user pressed 'cancel' there. mIsSigninRequired = true; if (mTraits != null) { mTraits.sessionID = null; mTraits.token = null; } } } break; } case ACTIVITY_ADVANCED_ROUTER_SETTINGS: { String url = data.getStringExtra(CLOUD_CONNECTION_HOST_PREFIX); Boolean useSmartBrowser = data.getBooleanExtra(EXTRAS_SMART_BROWSER_ON, false); if (!CLOUD_CONNECTION_HOST_PREFIX.contentEquals(url) || mUseSmartBrowser != useSmartBrowser) { CLOUD_CONNECTION_HOST_PREFIX = url; CLOUD_BROWSER_URL = CLOUD_CONNECTION_HOST_PREFIX; mUseSmartBrowser = useSmartBrowser; AuthPreferences.storeUseSmartBrowser(mUseSmartBrowser); if (useSmartBrowser) { CLOUD_BROWSER_URL = CLOUD_BROWSER_URL + CLOUD_CONNECTION_HOST_SMARTBROWSER_POSTFIX; } else { CLOUD_BROWSER_URL = CLOUD_BROWSER_URL + CLOUD_CONNECTION_HOST_BROWSER_POSTFIX; } AuthPreferences.storePreferredRouter(url); mStatusButtonView.setImageResource(R.drawable.connection_red); mCustomTabHost.clearAllHistory(); showSignIn(null, false); } Boolean clearCookies = data.getBooleanExtra(EXTRAS_CLEAR_COOKIES_ON, false); if (clearCookies) { CookieManager.getInstance().removeAllCookie(); } break; } case ACTIVITY_BOOKMARKS_AND_HISTORY: { String url = data.getStringExtra(EXTRAS_URL_KEY); if (!TextUtils.isEmpty(url)) { goToUrl(url); } break; } case ACTIVITY_AGENTS: { // Since the agent has changed, we can no longer use the old // history in WebViewClient with the old SessionID. mCustomTabHost.clearAllHistory(); mReloadButtonView.setEnabled(false); ConnectionTraits traits = (ConnectionTraits) data.getSerializableExtra(EXTRAS_TRAITS_KEY); if (traits != null && traits.sessionID != null) { mTraits.sessionID = traits.sessionID; mStatusButtonView.setImageResource(R.drawable.connection_green); // Should never be null if (traits.agent != null) { if (traits.agent.getAgentId() != null) { mTraits.agent.setAgentId(traits.agent.getAgentId()); // Switch to agent specific stored data. PersistenceManager.dropContent(PersistenceManager.ContentType.HISTORY); PersistenceManager.initialize(mTraits.agent.getAgentId()); } if (traits.agent.getDisplayName() != null) { mTraits.agent.setDisplayName(traits.agent.getDisplayName()); } } } break; } case ACTIVITY_CLIENT_STATUS_AND_DIAGNOSTICS: { String browse = data.getStringExtra(EXTRAS_BROWSE_TO_ROUTER_SYSTEM_PAGE_KEY); if (!(browse == null || browse.isEmpty())) mActiveWebView.loadUrl(CLOUD_CONNECTION_HOST_PREFIX + "system"); break; } } } catch (Exception e) { Utility.showAlertDialog(EnterpriseBrowserActivity.class.getSimpleName() + ".onActivityResult(): Failed. " + e.toString(), EnterpriseBrowserActivity.this); } }
From source file:com.citrus.sdk.CitrusClient.java
public synchronized void getCookie(String email, String password, final Callback<CitrusResponse> callback) { RetroFitClient.setInterCeptor();/* ww w . j a v a2s . com*/ EventBus.getDefault().register(CitrusClient.this); retrofitClient.getCookie(email, password, "true", new retrofit.Callback<String>() { @Override public void success(String s, Response response) { // NOOP // This method will never be called. } @Override public void failure(RetrofitError error) { EventBus.getDefault().unregister(CitrusClient.this); if (error.getResponse().getStatus() == HttpStatus.SC_INTERNAL_SERVER_ERROR) { //Invalid Password for COOKIE CitrusError citrusError = new CitrusError(ResponseMessages.ERROR_MESSAGE_INVALID_PASSWORD, Status.FAILED); callback.error(citrusError); } else { if (prepaidCookie != null) { cookieManager = CookieManager.getInstance(); PersistentConfig config = new PersistentConfig(mContext); if (config.getCookieString() != null) { cookieManager.getInstance().removeSessionCookie(); } CookieSyncManager.createInstance(mContext); config.setCookie(prepaidCookie); } else { Logger.d("PREPAID LOGIN UNSUCCESSFUL"); } // Since we have a got the cookie, we are giving the callback. sendResponse(callback, new CitrusResponse(ResponseMessages.SUCCESS_COOKIE_SIGNIN, Status.SUCCESSFUL)); } } }); }
From source file:com.dish.browser.activity.BrowserActivity.java
@SuppressLint("NewApi") @SuppressWarnings("deprecation") public void clearCookies() { // TODO Break out web storage deletion into its own option/action // TODO clear web storage for all sites that are visited in Incognito mode WebStorage storage = WebStorage.getInstance(); storage.deleteAllData();/*ww w .j a va 2s . co m*/ CookieManager c = CookieManager.getInstance(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { c.removeAllCookies(null); } else { CookieSyncManager.createInstance(this); c.removeAllCookie(); } }
From source file:com.codename1.impl.android.AndroidImplementation.java
private static CookieManager getCookieManager() { if (android.os.Build.VERSION.SDK_INT >= 21) { return CookieManager.getInstance(); }/* w ww . ja v a 2 s . c om*/ if (cookieManager == null) { CookieSyncManager.createInstance(getContext()); // Fixes a crash on Android 4.3 // https://stackoverflow.com/a/20552998/2935174 cookieManager = CookieManager.getInstance(); } return CookieManager.getInstance(); }