本文整理汇总了Java中android.webkit.CookieManager.getCookie方法的典型用法代码示例。如果您正苦于以下问题:Java CookieManager.getCookie方法的具体用法?Java CookieManager.getCookie怎么用?Java CookieManager.getCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.CookieManager
的用法示例。
在下文中一共展示了CookieManager.getCookie方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearCookiesForDomain
import android.webkit.CookieManager; //导入方法依赖的package包/类
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();
}
示例2: getCookieFromAppCookieManager
import android.webkit.CookieManager; //导入方法依赖的package包/类
public static String getCookieFromAppCookieManager(String url) throws MalformedURLException {
CookieManager cookieManager = CookieManager.getInstance();
if (cookieManager == null)
return null;
// 出錯點 1
cookieManager.setAcceptCookie(true);
String rawCookieHeader = null;
URL parsedURL = new URL(url);
// 出錯點 2
// Extract Set-Cookie header value from Android app CookieManager for this URL
rawCookieHeader = cookieManager.getCookie(parsedURL.getHost());
if (rawCookieHeader == null)
return null;
return rawCookieHeader;
}
示例3: clearCookiesForDomain
import android.webkit.CookieManager; //导入方法依赖的package包/类
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();
}
示例4: getExistingCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
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;
}
示例5: setCookies
import android.webkit.CookieManager; //导入方法依赖的package包/类
public static void setCookies(Context context, String url) {
String cookie1 = "letvclient_sig=" + MD5.toMd5(Global.DEVICEID + LetvConstant.MIYUE_ATTENDANCE);
String cookie2 = "letvclient_did=" + Global.DEVICEID;
CookieSyncManager syncManger = CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
String CookieStr = cookieManager.getCookie(url);
if (CookieStr == null || !CookieStr.contains("letvclient_did") || !CookieStr.contains("letvclient_sig")) {
cookieManager.setAcceptCookie(true);
cookieManager.setCookie(url, cookie1);
cookieManager.setCookie(url, cookie2);
syncManger.sync();
}
}
示例6: syncCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
/**
* 将cookie同步到WebView
*
* @param url WebView要加载的url
* @param cookie 要同步的cookie
* @return true:同步cookie成功;false:同步cookie失败
*/
public static boolean syncCookie(Context context, String url, String cookie) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(context);
}
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie(url, cookie);
String newCookie = cookieManager.getCookie(url);
return !TextUtils.isEmpty(newCookie);
}
示例7: clearCookieByUrlInternal
import android.webkit.CookieManager; //导入方法依赖的package包/类
private static void clearCookieByUrlInternal(String url, CookieManager pCookieManager) {
if (TextUtils.isEmpty(url)) {
return;
}
String cookieString = pCookieManager.getCookie(url);
Vector<String> cookie = getCookieNamesByUrl(cookieString);
if (cookie == null || cookie.isEmpty()) {
return;
}
int len = cookie.size();
for (int i = 0; i < len; i++) {
pCookieManager.setCookie(url, cookie.get(i) + "=-1");
}
pCookieManager.flush();
}
示例8: getCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
private String getCookie(String url) {
CookieManager cookieManager = CookieManager.getInstance();
return cookieManager.getCookie(url);
}
示例9: getCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
@Override
public String getCookie(String url) {
CookieManager cookieManager = CookieManager.getInstance();
return cookieManager.getCookie(url);
}
示例10: onKeyDown
import android.webkit.CookieManager; //导入方法依赖的package包/类
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
stopAudioAndVideo();
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(UIWebview.this);
cookieSyncManager.sync();
CookieManager cookieManager = CookieManager.getInstance();
if (cookieManager.getCookie(Constants.urlHost) == null && url != null && url.matches(".+login")) {
finish();
System.exit(0);
return true;
}
if (isFull) {
return super.onKeyDown(keyCode, event);
}
String currentUrl = webView.getUrl();
Log.d("currentUrl", currentUrl);
if (currentUrl.matches(".+newwin=1.*|.+error.html.+") || currentUrl.matches("^http.+")) {
Log.d("currentUrl", "false");
this.setResult(2002);
this.finish();
if (animate == 1) {
overridePendingTransition(R.anim.none, R.anim.push_bottom_out);
} else if (animate == 2) {
overridePendingTransition(R.anim.none, R.anim.slide_right_out);
}
return true;
}
else {
Log.d("currentUrl", "true");
this.runOnUiThread(new Runnable() {
@Override
public void run() {
webView.evaluateJavascript("history.go(-1)", null);
}
});
return false;
}
} else {
return super.onKeyDown(keyCode, event);
}
}
示例11: getCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
public static void getCookie(String url) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.getCookie(url);
}