List of usage examples for android.webkit CookieSyncManager createInstance
public static CookieSyncManager createInstance(Context context)
From source file:com.example.office365sample.MainActivity.java
public void clearCookies() { CookieSyncManager.createInstance(getApplicationContext()); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();/* w ww. j a v a 2s.c o m*/ CookieSyncManager.getInstance().sync(); }
From source file:org.catrobat.catroid.ui.WebViewActivity.java
@SuppressWarnings("deprecated") @SuppressLint("NewApi") public static void clearCookies(Context context) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); cookieSyncMngr.startSync();//from ww w . j a v a 2 s .com CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } else { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } }
From source file:com.google.android.gm.ay.java
public static void bk(final Context context) { final CookieSyncManager instance = CookieSyncManager.createInstance(context); CookieManager.getInstance().removeAllCookie(); instance.sync();//from www .j a v a 2s.c om }
From source file:ms.android.facebookSDK.Facebook.java
/** * Internal method to handle dialog-based authentication backend for * authorize().//from w ww .j a v 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:net.niyonkuru.koodroid.service.SessionService.java
/** * Save cookies for later use by a {@link WebView} *//* www . j a v a 2s . co m*/ private void saveCookies() { List<Cookie> cookies = mHttpClient.getCookieStore().getCookies(); if (cookies.isEmpty()) return; CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); for (Cookie cookie : cookies) { String url = (cookie.isSecure() ? "https://" : "http://") + Config.DOMAIN + cookie.getPath(); String value = cookie.getName() + "=" + cookie.getValue(); if (cookie.getDomain().startsWith(".")) { value += "; domain=" + cookie.getDomain(); } cookieManager.setCookie(url, value); } }
From source file:com.moki.touch.fragments.views.WebContent.java
public void cleanupHistory() { try {//from w w w. ja v a2s . c o m if (webView != null) { Log.i(TAG, "clean up history"); webView.clearHistory(); webView.clearFormData(); webView.clearCache(true); webView.clearSslPreferences(); webView.destroy(); if (context != null) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); } } } catch (Exception e) { Log.i(TAG, e.getMessage(), e); } }
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);// w w w . j a va 2 s. c om 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().//w ww . jav a 2 s . c om * * @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();/* w w w . j av a 2s . com*/ CookieSyncManager.getInstance().sync(); }
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// w w w . ja v a 2 s . c om */ @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(); }