Java Code Examples for android.webkit.CookieSyncManager#sync()
The following examples show how to use
android.webkit.CookieSyncManager#sync() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utility.java From facebook-api-android-maven with Apache License 2.0 | 6 votes |
private static void clearCookiesForDomain(Context context, String domain) { // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); CookieManager cookieManager = CookieManager.getInstance(); String cookies = cookieManager.getCookie(domain); if (cookies == null) { return; } String[] splitCookies = cookies.split(";"); for (String cookie : splitCookies) { String[] cookieParts = cookie.split("="); if (cookieParts.length > 0) { String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;"; cookieManager.setCookie(domain, newCookie); } } cookieManager.removeExpiredCookie(); }
Example 2
Source File: AuthorizationClient.java From FacebookNewsfeedSample-Android with Apache License 2.0 | 6 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult("User canceled log in."); } else { outcome = Result.createErrorResult(error.getMessage(), null); } } completeAndValidate(outcome); }
Example 3
Source File: Utility.java From kognitivo with Apache License 2.0 | 6 votes |
private static void clearCookiesForDomain(Context context, String domain) { // This is to work around a bug where CookieManager may fail to instantiate if // CookieSyncManager has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); CookieManager cookieManager = CookieManager.getInstance(); String cookies = cookieManager.getCookie(domain); if (cookies == null) { return; } String[] splitCookies = cookies.split(";"); for (String cookie : splitCookies) { String[] cookieParts = cookie.split("="); if (cookieParts.length > 0) { String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;"; cookieManager.setCookie(domain, newCookie); } } cookieManager.removeExpiredCookie(); }
Example 4
Source File: ProWebView.java From prowebview with Apache License 2.0 | 6 votes |
/** * Clear the cookies */ @SuppressWarnings("deprecation") public void clearCookies() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getContext()); cookieSyncMngr.startSync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } }
Example 5
Source File: AuthorizationClient.java From aws-mobile-self-paced-labs-samples with Apache License 2.0 | 6 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult("User canceled log in."); } else { outcome = Result.createErrorResult(error.getMessage(), null); } } completeAndValidate(outcome); }
Example 6
Source File: ProfileEditFragment.java From 4pdaClient-plus with Apache License 2.0 | 6 votes |
protected void onPostExecute(final Boolean success) { setLoading(false); if (isCancelled()) return; if (success) { showThemeBody(m_ThemeBody); } else { getSupportActionBar().setTitle(ex.getMessage()); m_WebView.loadDataWithBaseURL("https://4pda.ru/forum/", m_ThemeBody, "text/html", "UTF-8", null); AppLog.e(getMainActivity(), ex); } CookieSyncManager syncManager = CookieSyncManager.createInstance(m_WebView.getContext()); CookieManager cookieManager = CookieManager.getInstance(); for (HttpCookie cookie : Client.getInstance().getCookies()) { if (cookie.getDomain() != null) { cookieManager.setCookie(cookie.getDomain(), cookie.getName() + "=" + cookie.getValue()); } //cookieManager.setCookie(cookie.getTitle(),cookie.getValue()); } syncManager.sync(); }
Example 7
Source File: Utility.java From android-skeleton-project with MIT License | 6 votes |
private static void clearCookiesForDomain(Context context, String domain) { // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); CookieManager cookieManager = CookieManager.getInstance(); String cookies = cookieManager.getCookie(domain); if (cookies == null) { return; } String[] splitCookies = cookies.split(";"); for (String cookie : splitCookies) { String[] cookieParts = cookie.split("="); if (cookieParts.length > 0) { String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;"; cookieManager.setCookie(domain, newCookie); } } cookieManager.removeExpiredCookie(); }
Example 8
Source File: Utility.java From HypFacebook with BSD 2-Clause "Simplified" License | 6 votes |
private static void clearCookiesForDomain(Context context, String domain) { // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); CookieManager cookieManager = CookieManager.getInstance(); String cookies = cookieManager.getCookie(domain); if (cookies == null) { return; } String[] splitCookies = cookies.split(";"); for (String cookie : splitCookies) { String[] cookieParts = cookie.split("="); if (cookieParts.length > 0) { String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;"; cookieManager.setCookie(domain, newCookie); } } cookieManager.removeExpiredCookie(); }
Example 9
Source File: ForwardingCookieHandler.java From react-native-GPay with MIT License | 5 votes |
private static void possiblyWorkaroundSyncManager(Context context) { if (USES_LEGACY_STORE) { // This is to work around a bug where CookieManager may fail to instantiate if // CookieSyncManager has never been created. Note that the sync() may not be required but is // here of legacy reasons. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); } }
Example 10
Source File: LetvUtils.java From letv with Apache License 2.0 | 5 votes |
public static void setCookies(Context context, String url) { String cookie1 = "letvclient_sig=" + MD5.toMd5(Global.DEVICEID + LetvConstant.MIYUE_ATTENDANCE); String cookie2 = "letvclient_did=" + Global.DEVICEID; CookieSyncManager syncManger = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); String CookieStr = cookieManager.getCookie(url); if (CookieStr == null || !CookieStr.contains("letvclient_did") || !CookieStr.contains("letvclient_sig")) { cookieManager.setAcceptCookie(true); cookieManager.setCookie(url, cookie1); cookieManager.setCookie(url, cookie2); syncManger.sync(); } }
Example 11
Source File: SyncUserStateUtil.java From letv with Apache License 2.0 | 5 votes |
public static void setGameTokenCookie(Context context, String token) { CookieSyncManager syncManger = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie("http://api.game.letvstore.com", "sso_tk=" + token); syncManger.sync(); LogInfo.log("wlx", "game cookie = " + cookieManager.getCookie("http://api.game.letvstore.com")); }
Example 12
Source File: WebScraper.java From VehicleInfoOCR with GNU General Public License v3.0 | 5 votes |
public void clearCookies(){ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); }else{ CookieSyncManager cookieSync = CookieSyncManager.createInstance(context); cookieSync.startSync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSync.stopSync(); cookieSync.sync(); } }
Example 13
Source File: AuthorizationClient.java From android-skeleton-project with MIT License | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }
Example 14
Source File: AuthorizationClient.java From facebook-api-android-maven with Apache License 2.0 | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }
Example 15
Source File: Login.java From Slide with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstance) { overrideSwipeFromAnywhere(); super.onCreate(savedInstance); applyColorTheme(""); try { setContentView(R.layout.activity_login); } catch(Exception e){ finish(); return; } setupAppBar(R.id.toolbar, R.string.title_login, true, true); String[] scopes = { "identity", "modcontributors", "modconfig", "modothers", "modwiki", "creddits", "livemanage", "account", "privatemessages", "modflair", "modlog", "report", "modposts", "modwiki", "read", "vote", "edit", "submit", "subscribe", "save", "wikiread", "flair", "history", "mysubreddits", "wikiedit" }; if (Authentication.reddit == null) { new Authentication(getApplicationContext()); } final OAuthHelper oAuthHelper = Authentication.reddit.getOAuthHelper(); final Credentials credentials = Credentials.installedApp(CLIENT_ID, REDIRECT_URL); String authorizationUrl = oAuthHelper.getAuthorizationUrl(credentials, true, scopes).toExternalForm(); authorizationUrl = authorizationUrl.replace("www.", "i."); authorizationUrl = authorizationUrl.replace("%3A%2F%2Fi", "://www"); Log.v(LogUtil.getTag(), "Auth URL: " + authorizationUrl); final WebView webView = (WebView) findViewById(R.id.web); webView.clearCache(true); webView.clearHistory(); WebSettings webSettings = webView.getSettings(); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); webSettings.setDatabaseEnabled(true); webSettings.setMinimumFontSize(1); webSettings.setMinimumLogicalFontSize(1); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(this); cookieSyncMngr.startSync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { LogUtil.v(url); if (url.contains("code=")) { Log.v(LogUtil.getTag(), "WebView URL: " + url); // Authentication code received, prevent HTTP call from being made. webView.stopLoading(); new UserChallengeTask(oAuthHelper, credentials).execute(url); webView.setVisibility(View.GONE); } } }); webView.loadUrl(authorizationUrl); }
Example 16
Source File: AuthorizationClient.java From platform-friends-android with BSD 2-Clause "Simplified" License | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }
Example 17
Source File: AuthorizationClient.java From KlyphMessenger with MIT License | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }
Example 18
Source File: WebViewLoginMethodHandler.java From kognitivo with Apache License 2.0 | 4 votes |
void onWebDialogComplete(LoginClient.Request request, Bundle values, FacebookException error) { LoginClient.Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } try { AccessToken token = createAccessTokenFromWebBundle( request.getPermissions(), values, AccessTokenSource.WEB_VIEW, request.getApplicationId()); outcome = LoginClient.Result.createTokenResult( loginClient.getPendingRequest(), token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if // CookieSyncManager has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(loginClient.getActivity()); syncManager.sync(); saveCookieToken(token.getToken()); } catch (FacebookException ex) { outcome = LoginClient.Result.createErrorResult( loginClient.getPendingRequest(), null, ex.getMessage()); } } else { if (error instanceof FacebookOperationCanceledException) { outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(), "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing // results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(e2e); } loginClient.completeAndValidate(outcome); }
Example 19
Source File: AuthorizationClient.java From Klyph with MIT License | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }
Example 20
Source File: AuthorizationClient.java From barterli_android with Apache License 2.0 | 4 votes |
void onWebDialogComplete(AuthorizationRequest request, Bundle values, FacebookException error) { Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } AccessToken token = AccessToken .createFromWebBundle(request.getPermissions(), values, AccessTokenSource.WEB_VIEW); outcome = Result.createTokenResult(pendingRequest, token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager // has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(context); syncManager.sync(); saveCookieToken(token.getToken()); } else { if (error instanceof FacebookOperationCanceledException) { outcome = Result.createCancelResult(pendingRequest, "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format("%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = Result.createErrorResult(pendingRequest, null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(applicationId, e2e); } completeAndValidate(outcome); }