Java Code Examples for android.webkit.CookieSyncManager#createInstance()
The following examples show how to use
android.webkit.CookieSyncManager#createInstance() .
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: FacebookLoginActivity.java From facebooklogin 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 2
Source File: Util.java From CoolApk-Console with GNU General Public License v3.0 | 6 votes |
/** * @see <a href="http://stackoverflow.com/questions/28998241/how-to-clear-cookies-and-cache-of-webview-on-android-when-not-in-webview" /> * @param context */ @SuppressWarnings("deprecation") public static void clearCookies(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { CookieSyncManager cookieSyncMngr= CookieSyncManager.createInstance(context); cookieSyncMngr.startSync(); CookieManager cookieManager= CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } }
Example 3
Source File: Utility.java From platform-friends-android 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 4
Source File: EvernoteSession.java From EverMemo-EverNote with MIT License | 6 votes |
/** * Clear all stored authentication information. */ public void logOut(Context ctx) throws InvalidAuthenticationException { if(!isLoggedIn()) { throw new InvalidAuthenticationException("Must not call when already logged out"); } synchronized (this) { mAuthenticationResult.clear(SessionPreferences.getPreferences(ctx)); mAuthenticationResult = null; } // TODO The cookie jar is application scope, so we should only be removing // evernote.com cookies. CookieSyncManager.createInstance(ctx); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); }
Example 5
Source File: Utility.java From FacebookNewsfeedSample-Android 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 6
Source File: VKSdk.java From cordova-social-vk with Apache License 2.0 | 6 votes |
/** * Wipes out information about the access token and clears cookies for internal browse */ @SuppressLint("NewApi") public static void logout() { Context context = VKUIHelper.getApplicationContext(); if (Build.VERSION.SDK_INT < 21) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); } else { CookieManager.getInstance().removeAllCookies(null); } VKAccessToken.replaceToken(VKUIHelper.getApplicationContext(), null); updateLoginState(context); }
Example 7
Source File: TyApplication.java From tysq-android with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); mContext = this; initDagger(); initDb(); initDownload(); initUtils(); initEditor(); initBitFrame(); initUploading(); initVideo(); initCache(); if (UserCache.getDefault() != null) { Crashlytics.setUserIdentifier(UserCache.getDefault().getAccountId() + ""); } CookieSyncManager.createInstance(this); }
Example 8
Source File: InstagramSession.java From AndroidInstagram with Apache License 2.0 | 6 votes |
/** * Reset user data */ public void reset() { Editor editor = mSharedPref.edit(); editor.putString(ACCESS_TOKEN, ""); editor.putString(USERID, ""); editor.putString(USERNAME, ""); editor.putString(FULLNAME, ""); editor.putString(PROFILPIC, ""); editor.commit(); CookieSyncManager.createInstance(mContext); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); }
Example 9
Source File: SocialAuthAdapter.java From socialauth-android with MIT License | 5 votes |
/** * Internal method to handle dialog-based authentication backend for * authorize(). * * @param context * The Android Activity that will parent the auth dialog. * @param provider * Provider being authenticated * */ private void startDialogAuth(final Context context, final Provider provider) { CookieSyncManager.createInstance(context); Runnable runnable = new Runnable() { @Override public void run() { try { // Get Callback url url = socialAuthManager.getAuthenticationUrl(provider.toString(), provider.getCallBackUri()) + "&type=user_agent&display=touch"; handler.post(new Runnable() { @Override public void run() { Log.d("SocialAuthAdapter", "Loading URL : " + url); String callbackUri = provider.getCallBackUri(); Log.d("SocialAuthAdapter", "Callback URI : " + callbackUri); // start webview dialog new SocialAuthDialog(context, url, provider, dialogListener, socialAuthManager).show(); } }); } catch (Exception e) { dialogListener.onError(new SocialAuthError("URL Authentication error", e)); } } }; new Thread(runnable).start(); }
Example 10
Source File: HtmlWebViewActivity.java From AndroidWallet with GNU General Public License v3.0 | 5 votes |
@Override protected void onDestroy() { CookieSyncManager.createInstance(this); //Create a singleton CookieSyncManager within a context CookieManager cookieManager = CookieManager.getInstance(); // the singleton CookieManager instance cookieManager.removeAllCookie();// Removes all cookies. CookieSyncManager.getInstance().sync(); // forces sync manager to sync now binding.htmlWebView.setWebChromeClient(null); binding.htmlWebView.setWebViewClient(null); binding.htmlWebView.getSettings().setJavaScriptEnabled(false); binding.htmlWebView.destroy(); super.onDestroy(); }
Example 11
Source File: WebViewActivity.java From CloudReader with Apache License 2.0 | 5 votes |
/** * 同步cookie */ private void syncCookie(String url) { if (!TextUtils.isEmpty(url) && url.contains("wanandroid")) { try { CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie();// 移除 cookieManager.removeAllCookie(); String cookie = SPUtils.getString("cookie", ""); if (!TextUtils.isEmpty(cookie)) { String[] split = cookie.split(";"); for (int i = 0; i < split.length; i++) { cookieManager.setCookie(url, split[i]); } } // String cookies = cookieManager.getCookie(url); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { cookieManager.flush(); } else { CookieSyncManager.getInstance().sync(); } } catch (Exception e) { DebugUtil.error("==异常==", e.toString()); } } }
Example 12
Source File: NotificationsService.java From FaceSlim with GNU General Public License v2.0 | 5 votes |
/** CookieSyncManager was deprecated in API level 21. * We need it for API level lower than 21 though. * In API level >= 21 it's done automatically. */ @SuppressWarnings("deprecation") private void syncCookies() { if (Build.VERSION.SDK_INT < 21) { CookieSyncManager.createInstance(getApplicationContext()); CookieSyncManager.getInstance().sync(); } }
Example 13
Source File: QuickUtil.java From quickhybrid-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 给webview设置cookie * * @param context * @param url */ public static void setCookies(Context context, String url) { if (!TextUtils.isEmpty(url)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){ CookieSyncManager.createInstance( context); } CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie(); // 自动注入cookie,这个在使用cookie作为用户校验时有用 cookieManager.setCookie(url, "JSESSIONID=" + QuickUtil.getToken()); CookieSyncManager.getInstance().sync(); } }
Example 14
Source File: WebViewHelper.java From Android_Skin_2.0 with Apache License 2.0 | 5 votes |
public static void removeSessionCookie(Context context) { if (context != null) { CookieSyncManager.createInstance(context); CookieSyncManager.getInstance().startSync(); CookieManager.getInstance().removeSessionCookie(); } }
Example 15
Source File: DrawerFragment.java From android-atleap with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CookieSyncManager.createInstance(getActivity()); }
Example 16
Source File: QunarWebActvity.java From imsdk-android with MIT License | 4 votes |
public void synCookie() { //下面的变量都是暂时处理 日后逻辑清晰重新构成 Boolean isHistory = mUrl.contains("main_controller"); CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); if (isHistory) { cookieManager.removeAllCookie(); } if (from != null && from.equals(Constants.BundleValue.UC_LOGIN)) { cookieManager.removeAllCookie(); } if (!TextUtils.isEmpty(mUrl) && mUrl.contains(DOMAIN)) { String qvtStr = CurrentPreference.getInstance().getQvt(); boolean qvt = false; if (!TextUtils.isEmpty(qvtStr) && !isHistory) { QVTResponseResult qvtResponseResult = JsonUtils.getGson().fromJson(qvtStr, QVTResponseResult.class); if (qvtResponseResult.ret) { cookieManager.setCookie(DOMAIN, "_v=" + qvtResponseResult.data.vcookie + ";"); cookieManager.setCookie(DOMAIN, "_t=" + qvtResponseResult.data.tcookie + ";"); cookieManager.setCookie(DOMAIN, "_q=" + qvtResponseResult.data.qcookie + ";"); cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";"); qvt = true; } } // if (!isHistory) { // if (!qvt) { // cookieManager.setCookie(DOMAIN, "_v=;"); // cookieManager.setCookie(DOMAIN, "_t=;"); // cookieManager.setCookie(DOMAIN, "_q=;"); // cookieManager.setCookie(DOMAIN, "q_d=;"); // } // } } if (mUrl.contains("/package/plts/dashboard")) { cookieManager.setCookie(DOMAIN, "q_u=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "q_nm=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";"); } if(isVideoAudioCall){ cookieManager.setCookie(DOMAIN, "_caller=" + QtalkStringUtils.parseId(videoCaller) + ";"); cookieManager.setCookie(DOMAIN, "_callee=" + QtalkStringUtils.parseId(videoCallee) + ";"); cookieManager.setCookie(DOMAIN, "_calltime=" + System.currentTimeMillis() + ";"); cookieManager.setCookie(DOMAIN, "u=" + CurrentPreference.getInstance().getUserid() + ";"); }else { cookieManager.setCookie(DOMAIN, "_caller=;"); cookieManager.setCookie(DOMAIN, "_callee=;"); cookieManager.setCookie(DOMAIN, "_calltime=;"); cookieManager.setCookie(DOMAIN, "u=;"); } //默认种qckey cookieManager.setCookie(DOMAIN, "q_ckey=" + Protocol.getCKEY() + ";"); if (QtalkSDK.getInstance().isLoginStatus()) { cookieManager.setCookie(DOMAIN, "_u=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "q_u=" + CurrentPreference.getInstance().getUserid() + ";"); cookieManager.setCookie(DOMAIN, "_k=" + CurrentPreference.getInstance().getVerifyKey() + ";"); cookieManager.setCookie(DOMAIN, "q_d=" + QtalkNavicationService.getInstance().getXmppdomain() + ";"); } else { cookieManager.setCookie(DOMAIN, "_u=;"); cookieManager.setCookie(DOMAIN, "_k=;"); cookieManager.setCookie(DOMAIN, "q_d=;"); } if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { cookieManager.flush(); } else { CookieSyncManager.getInstance().sync(); } Logger.i("QunarWebActvity getCookie:"+ cookieManager.getCookie(DOMAIN)); }
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: ThreadViewFragment.java From something.apk with MIT License | 4 votes |
@Override public void viewCreated(View frag, Bundle savedInstanceState) { navPrev = (ImageView) frag.findViewById(R.id.threadview_prev); navNext = (ImageView) frag.findViewById(R.id.threadview_next); navPageBar = (TextView) frag.findViewById(R.id.threadview_page); navPageBar.setOnClickListener(this); navNext.setOnClickListener(this); navPrev.setOnClickListener(this); pfbContainer = frag.findViewById(R.id.threadview_pullfrombottom); pfbTitle = (TextView) frag.findViewById(R.id.threadview_pullfrombottom_title); pfbProgressbar = (ProgressBar) frag.findViewById(R.id.threadview_pullfrombottom_progress); threadView = (WebView) frag.findViewById(R.id.ptr_webview); initWebview(); updateNavbar(); CookieManager cookieManager = CookieManager.getInstance(); if (!SomeUtils.isLollipop()) { CookieSyncManager.createInstance(getContext()); } cookieManager.setAcceptCookie(true); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_USER_ID)); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_USER_PASS)); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_SESSION_HASH)); cookieManager.setCookie(Constants.COOKIE_DOMAIN, SomePreferences.getCookie(Constants.COOKIE_SESSION_ID)); if (!SomeUtils.isLollipop()) { CookieSyncManager.getInstance().sync(); } if(savedInstanceState != null && savedInstanceState.containsKey("thread_html")){ loadThreadState(savedInstanceState); }else{ Intent intent = getActivity().getIntent(); threadId = intent.getIntExtra("thread_id", 0); page = intent.getIntExtra("thread_page", 0); postId = intent.getLongExtra("post_id", 0); if(threadId > 0 || postId > 0){ setTitle("Loading..."); startRefresh(); } } }
Example 19
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 20
Source File: CookieUtils.java From BigApp_Discuz_Android with Apache License 2.0 | 4 votes |
public static void syncCookie(Context context) { //尼玛 获取cookie的时候先手动同步,不然会跪 CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context); cookieSyncManager.startSync(); }