List of usage examples for android.webkit CookieManager getInstance
public static CookieManager getInstance()
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 w w . java 2s . 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 ww w . java 2 s. c o m }
From source file:com.blueserial.MyApplication.java
@Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); CookieSyncManager.createInstance(this); CookieManager.getInstance().setAcceptCookie(true); }
From source file:com.jaspersoft.android.jaspermobile.cookie.LegacyCookieManager.java
@Override public void semanticConfiguration(String targetDomain) { CookieSyncManager.createInstance(getContext()); final CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeSessionCookie(); cookieManager.setCookie(targetDomain, StringUtils.join(getCookieStore(), ";")); CookieSyncManager.getInstance().sync(); }
From source file:biz.varkon.shelvesom.util.CookieStore.java
public String getCookie(String url) { final CookieManager cookieManager = CookieManager.getInstance(); String cookie = cookieManager.getCookie(url); if (cookie == null || cookie.length() == 0) { final HttpHead head = new HttpHead(url); HttpEntity entity = null;//w w w . j a v a 2 s. c om try { final HttpResponse response = HttpManager.execute(head); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { entity = response.getEntity(); final Header[] cookies = response.getHeaders("set-cookie"); for (Header cooky : cookies) { cookieManager.setCookie(url, cooky.getValue()); } CookieSyncManager.getInstance().sync(); cookie = cookieManager.getCookie(url); } } catch (IOException e) { Log.e(LOG_TAG, "Could not retrieve cookie", e); } finally { if (entity != null) { try { entity.consumeContent(); } catch (IOException e) { Log.e(LOG_TAG, "Could not retrieve cookie", e); } } } } return cookie; }
From source file:com.jaspersoft.android.jaspermobile.cookie.LollipopCookieManager.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override// www .jav a2 s . c om protected void semanticConfiguration(final String targetDomain) { final CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeSessionCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { cookieManager.setCookie(targetDomain, StringUtils.join(getCookieStore(), ";")); CookieManager.getInstance().flush(); } }); }
From source file:com.kinsights.cookies.Cookies.java
public void clear() { CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeExpiredCookie(); cookieManager.removeSessionCookie(); cookieManager.removeAllCookie();/*from w w w. ja v a 2s . c o m*/ }
From source file:com.knowledgecode.cordova.websocket.ConnectionTask.java
/** * Set cookies, if any./*w w w.j a v a 2 s . com*/ * * @param cookies * @param url */ private static void setCookie(Map<String, String> cookies, String url) { String cookie = CookieManager.getInstance().getCookie(url); if (cookie != null) { for (String c : cookie.split(";")) { String[] pair = c.split("="); if (pair.length == 2) { cookies.put(pair[0], pair[1]); } } } }
From source file:org.geometerplus.android.fbreader.network.auth.WebAuthorisationScreen.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_PROGRESS); SQLiteCookieDatabase.init(this); CookieSyncManager.createInstance(getApplicationContext()); CookieManager.getInstance().removeAllCookie(); final Intent intent = getIntent(); final Uri data = intent.getData(); if (data == null || data.getHost() == null) { finish();//from ww w . j a v a2 s . co m return; } final String completeUrl = intent.getStringExtra(COMPLETE_URL_KEY); OrientationUtil.setOrientation(this, intent); final WebView view = new WebView(this); view.getSettings().setJavaScriptEnabled(true); view.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { setProgress(progress * 100); } }); view.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { setTitle(url); if (url != null && url.startsWith(completeUrl)) { final HashMap<String, String> cookies = new HashMap<String, String>(); final String cookieString = CookieManager.getInstance().getCookie(url); if (cookieString != null) { // cookieString is a string like NAME=VALUE [; NAME=VALUE] for (String pair : cookieString.split(";")) { final String[] parts = pair.split("=", 2); if (parts.length != 2) { continue; } cookies.put(parts[0].trim(), parts[1].trim()); } } storeCookies(data.getHost(), cookies); WebAuthorisationScreen.this.setResult(RESULT_OK); finish(); } } public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { if (android.os.Build.VERSION.SDK_INT == android.os.Build.VERSION_CODES.ECLAIR_MR1) { // hack for auth problem in android 2.1 handler.proceed(); } else { super.onReceivedSslError(view, handler, error); } } }); setContentView(view); view.loadUrl(intent.getDataString()); }