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(); }
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(); }
private void setCookie(Context context, String domain, String sessionCookie) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); if (sessionCookie != null) { // delete old cookies cookieManager.removeSessionCookie(); } try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } cookieManager.setCookie(domain, sessionCookie); CookieSyncManager.createInstance(context); CookieSyncManager.getInstance().sync(); }
public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().flush(); } else { CookieSyncManager.getInstance().sync(); } // https://issues.apache.org/jira/browse/CB-11248 view.clearFocus(); view.requestFocus(); try { JSONObject obj = new JSONObject(); obj.put("type", LOAD_STOP_EVENT); obj.put("url", url); sendUpdate(obj, true); } catch (JSONException ex) { LOG.d(LOG_TAG, "Should never happen"); } }
/** * 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(); } }
private String getExistingCookie() { try { CookieSyncManager.createInstance(context); CookieManager cm = CookieManager.getInstance(); if (cm != null) { String wvcookie = cm.getCookie(Settings.COOKIE_DOMAIN); if (!TextUtils.isEmpty(wvcookie)) { String[] existingCookies = wvcookie.split("; "); for (String cookie : existingCookies) { if (cookie != null && cookie.contains(Settings.AN_UUID)) { return cookie; } } } } } catch (Exception e) { } return null; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mSpinner = new ProgressDialog(getContext()); mSpinner.requestWindowFeature(Window.FEATURE_NO_TITLE); mSpinner.setMessage("Loading..."); mContent = new LinearLayout(getContext()); mContent.setOrientation(LinearLayout.VERTICAL); setUpTitle(); setUpWebView(); Display display = getWindow().getWindowManager().getDefaultDisplay(); final float scale = getContext().getResources().getDisplayMetrics().density; float[] dimensions = (display.getWidth() < display.getHeight()) ? DIMENSIONS_PORTRAIT : DIMENSIONS_LANDSCAPE; addContentView(mContent, new FrameLayout.LayoutParams((int) (dimensions[0] * scale + 0.5f), (int) (dimensions[1] * scale + 0.5f))); CookieSyncManager.createInstance(getContext()); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); }
private static void toSyncCookies() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.getInstance().sync(); return; } AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() { @Override public void run() { if (SysUtils.hasLollipop()) CookieManager.getInstance().flush(); } }); }
protected void sendResponseMessage(HttpResponse response) { super.sendResponseMessage(response); Header[] headers = response.getHeaders("Set-Cookie"); if (headers != null && headers.length > 0) { CookieSyncManager.createInstance(this.val$context).sync(); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); instance.removeSessionCookie(); String mm = ""; for (Header header : headers) { String[] split = header.toString().split("Set-Cookie:"); EALogger.i("正式登录", "split[1]===>" + split[1]); instance.setCookie(Constants.THIRDLOGIN, split[1]); int index = split[1].indexOf(";"); if (TextUtils.isEmpty(mm)) { mm = split[1].substring(index + 1); EALogger.i("正式登录", "mm===>" + mm); } } EALogger.i("正式登录", "split[1222]===>COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.THIRDLOGIN, "COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.THIRDLOGIN, "COOKIE_APP_ID=" + LemallPlatform.getInstance().getmAppInfo().getId() + ";" + mm); CookieSyncManager.getInstance().sync(); this.val$iLetvBrideg.reLoadWebUrl(); } }
protected void sendResponseMessage(HttpResponse response) { super.sendResponseMessage(response); Header[] headers = response.getHeaders("Set-Cookie"); if (headers != null && headers.length > 0) { CookieSyncManager.createInstance(LemallPlatform.getInstance().getContext()).sync(); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); instance.removeSessionCookie(); String mm = ""; for (Header header : headers) { String[] split = header.toString().split("Set-Cookie:"); EALogger.i("游客登录", "split[1]===>" + split[1]); instance.setCookie(Constants.GUESTLOGIN, split[1]); int index = split[1].indexOf(";"); if (TextUtils.isEmpty(mm)) { mm = split[1].substring(index + 1); EALogger.i("正式登录", "mm===>" + mm); } } EALogger.i("游客登录", "split[11]===>COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.GUESTLOGIN, "COOKIE_DEVICE_ID=" + LemallPlatform.getInstance().uuid + ";" + mm); instance.setCookie(Constants.THIRDLOGIN, "COOKIE_APP_ID=" + LemallPlatform.getInstance().getmAppInfo().getId() + ";" + mm); CookieSyncManager.getInstance().sync(); this.val$iLetvBrideg.reLoadWebUrl(); } }
public static void a(Context context, String str, String str2, String str3, String str4) { if (!TextUtils.isEmpty(str)) { CookieSyncManager.createInstance(context); CookieManager instance = CookieManager.getInstance(); instance.setAcceptCookie(true); String str5 = null; if (Uri.parse(str).getHost().toLowerCase().endsWith(".qq.com")) { str5 = ".qq.com"; } instance.setCookie(str, b("logintype", "MOBILEQ", str5)); instance.setCookie(str, b("qopenid", str2, str5)); instance.setCookie(str, b("qaccesstoken", str3, str5)); instance.setCookie(str, b("openappid", str4, str5)); CookieSyncManager.getInstance().sync(); } }
private static void saveCookie(String url){ String cookie = CookieManager.getInstance().getCookie(url); if(cookie !=null && !cookie.equals("")){ String[] cookies = cookie.split(";"); for(int i=0; i< cookies.length; i++){ String[] nvp = cookies[i].split("="); BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]); //c.setVersion(0); c.setDomain("kyfw.12306.cn"); MyCookieStore myCookieStore = null; if (MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore() instanceof MyCookieStore){ myCookieStore = (MyCookieStore)MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore(); } if (myCookieStore != null){ myCookieStore.addCookie(c); } } } CookieSyncManager.getInstance().sync(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //清除cookie CookieSyncManager.createInstance(WebViewActivity.this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); setContentView(R.layout.activity_webview); mWebView = (WebView) findViewById(R.id.login_webview); mIntent = getIntent(); mUrl = mIntent.getStringExtra("extr_url"); mProgress = (ProgressBar) findViewById(R.id.login_webview_progress); init(); }
/** * Flushes auth state when a call to logout is made. * * @param context {@link Context} */ public void logout(Context context) { this.removeFromSecuredPreferences(context, LI_DEFAULT_SDK_SETTINGS); this.removeFromSecuredPreferences(context, LI_AUTH_STATE); this.removeFromSecuredPreferences(context, LI_DEVICE_ID); this.removeFromSecuredPreferences(context, LI_RECEIVER_DEVICE_ID); this.removeFromSecuredPreferences(context, LiCoreSDKConstants.LI_SHARED_PREFERENCES_NAME); // For clearing cookies, if the android OS is Lollipop (5.0) and above use new way of using CookieManager else use the deprecate methods for older versions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { Log.d(LiCoreSDKConstants.LI_LOG_TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1)); CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { Log.d(LiCoreSDKConstants.LI_LOG_TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1)); CookieSyncManager cookieSyncMngr= CookieSyncManager.createInstance(context); cookieSyncMngr.startSync(); CookieManager cookieManager= CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } this.liAuthState = null; }
public void run() { try { Message message = new Message(); message.what = 2; if ("none".equals(DeviceHelper.getInstance(this.a.activity).getDetailNetworkTypeForStatic())) { message.arg1 = 1; UIHandler.sendMessage(message, this.a); return; } if (ShareSDK.isRemoveCookieOnAuthorize()) { CookieSyncManager.createInstance(this.a.activity); CookieManager.getInstance().removeAllCookie(); } message.obj = this.a.a.getAuthorizeUrl(); UIHandler.sendMessage(message, this.a); } catch (Throwable th) { Ln.e(th); } }
public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().flush(); } else { CookieSyncManager.getInstance().sync(); } try { JSONObject obj = new JSONObject(); obj.put("type", LOAD_STOP_EVENT); obj.put("url", url); sendUpdate(obj, true); } catch (JSONException ex) { LOG.d(LOG_TAG, "Should never happen"); } }
/** * @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(); } }
@SuppressWarnings("deprecation") private String[] collectCookies() { String cookies = CookieManager.getInstance().getCookie(Endpoints.BASE_URL); if (cookies == null || cookies.isEmpty()) { return null; } //See: http://stackoverflow.com/questions/28998241/how-to-clear-cookies-and-cache-of-webview-on-android-when-not-in-webview if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(getActivity().getApplicationContext()); cookieSyncMngr.startSync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } return cookies.split(" "); }
public void reset() { Editor editor = mSharedPref.edit(); editor.putString(ACCESS_TOKEN, ""); editor.putString(USERID, ""); editor.putString(USERNAME, ""); editor.putString(FULLNAME, ""); editor.putString(PROFILPIC, ""); editor.putInt(FOLLOW,0); editor.putInt(FOLLOWED,0); editor.commit(); CookieSyncManager.createInstance(mContext); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); }
public static void syncCookie(Context context) { PersistentCookieStore cookieStore = new PersistentCookieStore(context); List<Cookie> cookies = cookieStore.getCookies(); CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); for (int i = 0; i < cookies.size(); i++) { Cookie eachCookie = cookies.get(i); cookieManager.setCookie(Global.HOST, String.format("%s=%s; Domain=%s; Path=%s; Secure; HttpOnly", eachCookie.getName(), eachCookie.getValue(), eachCookie.getDomain(), eachCookie.getPath())); } CookieSyncManager.getInstance().sync(); }
public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); // CB-10395 InAppBrowser's WebView not storing cookies reliable to local device storage if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { CookieManager.getInstance().flush(); } else { CookieSyncManager.getInstance().sync(); } try { JSONObject obj = new JSONObject(); obj.put("type", LOAD_STOP_EVENT); obj.put("url", url); sendUpdate(obj, true); } catch (JSONException ex) { Log.d(LOG_TAG, "Should never happen"); } }
@Override public void userLoaded(User user) { mSpinner.setVisibility(View.GONE); Formatter.displayUser(mUserDetails, user); final Bundle bundle = new Bundle(); bundle.putString(Analytics.TAG_LOGIN, Analytics.VALUE_SUCCESS); mAnalytics.logEvent(FirebaseAnalytics.Event.LOGIN, bundle); new Handler().postDelayed(() -> { CookieSyncManager.createInstance(this); final CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); startActivity(mLaunchIntent); overridePendingTransition(R.anim.slide_up, R.anim.none); finish(); }, 1500); }
@SuppressLint("SetJavaScriptEnabled") @Override public void onCreate(Bundle savedInstanceState) { Log_OC.v(TAG, "onCreate, savedInstanceState is " + savedInstanceState); super.onCreate(savedInstanceState); setRetainInstance(true); CookieSyncManager.createInstance(getActivity().getApplicationContext()); if (savedInstanceState == null) { mInitialUrl = getArguments().getString(ARG_INITIAL_URL); mTargetUrl = getArguments().getString(ARG_TARGET_URL); } else { mInitialUrl = savedInstanceState.getString(ARG_INITIAL_URL); mTargetUrl = savedInstanceState.getString(ARG_TARGET_URL); } setStyle(DialogFragment.STYLE_NO_TITLE, R.style.synox_Dialog); }
@SuppressWarnings("deprecation") public static void clearCookies(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { //Log.d(C.TAG, "Using clearCookies code for API >=" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1)); CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } else { // Log.d(C.TAG, "Using clearCookies code for API <" + String.valueOf(Build.VERSION_CODES.LOLLIPOP_MR1)); CookieSyncManager cookieSyncMngr=CookieSyncManager.createInstance(context); cookieSyncMngr.startSync(); CookieManager cookieManager=CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } }
public static void syncWebViewCookies(@NonNull Context context, @NonNull CookieStore cookieStore) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie(); cookieManager.removeAllCookie(); List<URI> urls = cookieStore.getURIs(); for (URI url : urls) { List<HttpCookie> cookies = cookieStore.get(url); for (HttpCookie cookie : cookies) { cookieManager.setCookie(url.toString(), cookie.toString()); } L.w("Cookies", cookieManager.getCookie(url.toString())); } CookieSyncManager.getInstance().sync(); }
/** * 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); }
/** * Clear cookies * @param context 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(); } }