List of usage examples for android.webkit CookieSyncManager createInstance
public static CookieSyncManager createInstance(Context context)
From source file:Main.java
public static void removeAllCookies(Context context) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();//from w w w . j a v a 2s. c o m }
From source file:Main.java
public static String getCookieValue(Context context, String url, String key) { CookieSyncManager csm = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); csm.sync();/*from w w w .j a v a2s . c o m*/ String cookieStr = cookieManager.getCookie(url); System.out.println("========cookied:" + cookieStr); String[] strs = cookieStr.split(";"); String value = null; for (String string : strs) { if (string.trim().startsWith(key)) { value = string.substring(string.indexOf("=") + 1); break; } } return value; }
From source file:Main.java
public static void clearCookies(Context context) { @SuppressWarnings("unused") CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();/* w w w . j a v a2 s . co m*/ }
From source file:Main.java
@SuppressWarnings("deprecation") public static void clearCookies(Context context) { if (Build.VERSION.SDK_INT >= 21) { try {// www . j av a 2 s. c o m CookieManager.getInstance().removeAllCookies(null); CookieManager.getInstance().flush(); } catch (Exception e) { } } else { try { CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); cookieSyncMngr.startSync(); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); cookieManager.removeSessionCookie(); cookieSyncMngr.stopSync(); cookieSyncMngr.sync(); } catch (Exception e) { } } }
From source file:Main.java
public static void clearCookies(Context context) { // Edge case: an illegal state exception is thrown if an instance of // CookieSyncManager has not be created. CookieSyncManager is normally // created by a WebKit view, but this might happen if you start the // app, restore saved state, and click logout before running a UI // dialog in a WebView -- in which case the app crashes try {/*from ww w . ja v a 2 s. c o m*/ @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); } catch (Exception ex) { } }
From source file:Main.java
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();/*from ww w .ja v a 2 s . c o m*/ 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(); }
From source file:Main.java
public static void setCookie(Context context, String url) { FileInputStream in = null;//from w w w . ja v a 2 s . co m try { in = context.openFileInput(TAXICOOKIE_FILE); } catch (FileNotFoundException e) { e.printStackTrace(); } if (in == null) { Log.w(TAG, "saveCookie: Cannot open file: " + TAXICOOKIE_FILE); } BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String cookieStr = null; try { cookieStr = reader.readLine(); reader.close(); } catch (IOException e) { e.printStackTrace(); } Log.d(TAG, "cookieStr: " + cookieStr); if (cookieStr == null) { return; } CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeSessionCookie(); cookieManager.setCookie(url, cookieStr); CookieSyncManager.getInstance().sync(); }
From source file:Main.java
public static void clearCookies(Context context) { // Edge case: an illegal state exception is thrown if an instance of // CookieSyncManager has not be created. CookieSyncManager is normally // created by a WebKit view, but this might happen if you start the // app, restore saved state, and click logout before running a UI // dialog in a WebView -- in which case the app crashes @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();/* w ww . j ava 2 s .c o m*/ }
From source file:biz.varkon.shelvesom.util.CookieStore.java
public static void initialize(Context context) { CookieSyncManager.createInstance(context); CookieManager.getInstance().removeExpiredCookie(); }
From source file:Main.java
@SuppressWarnings("deprecation") private static void removeAllCookiesV14(Context context) { CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie();//from w ww. ja va 2 s . co m }