List of usage examples for android.webkit CookieManager getCookie
@SystemApi public synchronized String getCookie(WebAddress uri)
From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // cookies are automatically saved, we don't want that CookieManager cookieManager = CookieManager.getInstance(); String cookie = cookieManager.getCookie("https://github.com/"); outState.putString(ARG_GITHUB_COOKIE, cookie); }
From source file:ti.modules.titanium.network.NetworkModule.java
/** * Gets all the cookies with the domain, path and name matched with the given values. If name is null, gets all the cookies with * the domain and path matched.//from www. j a v a 2 s .c om * @param domain the domain of the cookie to get. It is case-insensitive. * @param path the path of the cookie to get. It is case-sensitive. * @param name the name of the cookie to get. It is case-sensitive. * @return an array of cookies only with name and value specified. If name is null, returns all the cookies with the domain and path matched. */ @Kroll.method public CookieProxy[] getSystemCookies(String domain, String path, String name) { if (domain == null || domain.length() == 0) { if (Log.isDebugModeEnabled()) { Log.e(TAG, "Unable to get the HTTP cookies. Need to provide a valid domain."); } return null; } if (path == null || path.length() == 0) { path = "/"; } ArrayList<CookieProxy> cookieList = new ArrayList<CookieProxy>(); CookieSyncManager.createInstance(TiApplication.getInstance().getRootOrCurrentActivity()); CookieManager cookieManager = CookieManager.getInstance(); String url = domain.toLowerCase() + path; String cookieString = cookieManager.getCookie(url); // The cookieString is in the format of NAME=VALUE[; // NAME=VALUE] if (cookieString != null) { String[] cookieValues = cookieString.split("; "); for (int i = 0; i < cookieValues.length; i++) { String[] pair = cookieValues[i].split("=", 2); String cookieName = pair[0]; String value = pair.length == 2 ? pair[1] : null; if (name == null || cookieName.equals(name)) { cookieList.add(new CookieProxy(cookieName, value, null, null)); } } } if (!cookieList.isEmpty()) { return cookieList.toArray(new CookieProxy[cookieList.size()]); } return null; }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Vector getCookiesForURL(String url) { if (isUseNativeCookieStore()) { try {/*from w ww . java2s .com*/ URI uri = new URI(url); CookieManager mgr = getCookieManager(); mgr.removeExpiredCookie(); String domain = uri.getHost(); String cookieStr = mgr.getCookie(url); if (cookieStr != null) { String[] cookies = cookieStr.split(";"); int len = cookies.length; Vector out = new Vector(); for (int i = 0; i < len; i++) { Cookie c = new Cookie(); String[] parts = cookies[i].split("="); c.setName(parts[0].trim()); if (parts.length > 1) { c.setValue(parts[1].trim()); } else { c.setValue(""); } c.setDomain(domain); out.add(c); } return out; } } catch (Exception ex) { com.codename1.io.Log.e(ex); } return new Vector(); } return super.getCookiesForURL(url); }