本文整理汇总了Java中android.webkit.CookieManager.setCookie方法的典型用法代码示例。如果您正苦于以下问题:Java CookieManager.setCookie方法的具体用法?Java CookieManager.setCookie怎么用?Java CookieManager.setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.CookieManager
的用法示例。
在下文中一共展示了CookieManager.setCookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
示例3: setCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
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();
}
示例4: sendResponseMessage
import android.webkit.CookieManager; //导入方法依赖的package包/类
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();
}
}
示例5: a
import android.webkit.CookieManager; //导入方法依赖的package包/类
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();
}
}
示例6: syncCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
public static void syncCookie(String url, String cookies) {
CookieManager mCookieManager = CookieManager.getInstance();
if (mCookieManager != null) {
mCookieManager.setCookie(url, cookies);
toSyncCookies();
}
}
示例7: saveUserSessionId
import android.webkit.CookieManager; //导入方法依赖的package包/类
public void saveUserSessionId(String userSessionId){
// save to cookie manager
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie(CMBCHINA_BASIC_URL, "userSessionId=" +userSessionId);
CookieSyncManager.getInstance().sync();
// save to sharedpreference
SharedPreferenceHelper.getInstance(getApplicationContext()).saveString(CMBCHINA_SHARED_PERFERENCE_KEY_USER_SESSION_ID,userSessionId);
}
示例8: setCookies
import android.webkit.CookieManager; //导入方法依赖的package包/类
/**
* 给webview设置cookie
*
* @param context
* @param url
*/
public static void setCookies(Context context, String url) {
if (!TextUtils.isEmpty(url)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
CookieSyncManager.createInstance( context);
}
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
// 自动注入cookie,这个在使用cookie作为用户校验时有用
cookieManager.setCookie(url, "JSESSIONID=" + QuickUtil.getToken());
CookieSyncManager.getInstance().sync();
}
}
示例9: setUserCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
public void setUserCookie(String cookie) {
CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(activity);
cookieSyncManager.sync();
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setCookie(Constants.urlHost, cookie);
CookieSyncManager.getInstance().sync();
}
示例10: 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);
}
示例11: handleMessage
import android.webkit.CookieManager; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
PortalActivity activity = mActivityRef.get();
if (activity == null || activity.isFinishing()) {
return;
}
WebView webview = (WebView) activity
.findViewById(R.id.webview);
switch (msg.what) {
case BaseRunnable.REFRESH:
java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
CookieHandler.getDefault()).getCookieStore();
if (rawCookieStore != null) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
try {
URI uri = new URI(PORTAL_URL);
for (HttpCookie cookie : rawCookieStore.get(uri)) {
String cookieString = cookie.getName() + "="
+ cookie.getValue() + "; domain="
+ cookie.getDomain();
cookieManager.setCookie(PORTAL_URL + "myPortal.do",
cookieString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
webview.loadUrl(PORTAL_URL + "myPortal.do");
break;
case BaseRunnable.ERROR:
webview.loadUrl(PORTAL_URL);
break;
}
activity.dismissProgressDialog();
Toast.makeText(activity, R.string.web_back_hint, Toast.LENGTH_LONG)
.show();
}
示例12: handleMessage
import android.webkit.CookieManager; //导入方法依赖的package包/类
@Override
public void handleMessage(Message msg) {
PortalFragment fragment = mActivityRef.get();
if (fragment == null) {
return;
}
WebView webview = (WebView) fragmentView
.findViewById(R.id.webview);
switch (msg.what) {
case BaseRunnable.REFRESH:
java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
CookieHandler.getDefault()).getCookieStore();
if (rawCookieStore != null) {
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
try {
URI uri = new URI(PORTAL_URL);
for (HttpCookie cookie : rawCookieStore.get(uri)) {
String cookieString = cookie.getName() + "="
+ cookie.getValue() + "; domain="
+ cookie.getDomain();
cookieManager.setCookie(PORTAL_URL + "myPortal.do",
cookieString);
}
} catch (Exception e) {
e.printStackTrace();
}
}
webview.loadUrl(PORTAL_URL + "aptreeList.do");
break;
case BaseRunnable.ERROR:
webview.loadUrl(PORTAL_URL);
break;
}
fragment.dismissProgressDialog();
Toast.makeText(fragment.getContext(), R.string.web_back_hint, Toast.LENGTH_SHORT)
.show();
}
示例13: setCookie
import android.webkit.CookieManager; //导入方法依赖的package包/类
@Override
public boolean setCookie(String url, List<String> cookies) {
if (!TextUtils.isEmpty(url) && cookies != null && cookies.size() > 0) {
CookieManager cookieManager = CookieManager.getInstance();
for (String cookie : cookies) {
cookieManager.setCookie(url, cookie);
}
return true;
}
return false;
}
示例14: httpCookieSync
import android.webkit.CookieManager; //导入方法依赖的package包/类
/**
* Synchronize the uuid2 cookie to the Webview Cookie Jar
* This is only done if there is no present cookie.
*
* @param headers headers to extract cookies from for syncing
*/
@SuppressWarnings("deprecation")
private void httpCookieSync(Map<String, List<String>> headers) {
if (headers == null || headers.isEmpty()) return;
CookieManager cm = CookieManager.getInstance();
if (cm == null) {
LogUtil.i(Settings.TAG, "Unable to find a CookieManager");
return;
}
try {
String existingUUID = getExistingCookie();
for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String key = entry.getKey();
// Only "Set-cookie" and "Set-cookie2" pair will be parsed
if (key != null && (key.equalsIgnoreCase(Settings.VERSION_ZERO_HEADER)
|| key.equalsIgnoreCase(Settings.VERSION_ONE_HEADER))) {
for (String cookieStr : entry.getValue()) {
if (!TextUtils.isEmpty(cookieStr) && cookieStr.contains(Settings.AN_UUID)) {
// pass uuid2 to WebView Cookie jar if it's empty or outdated
if (existingUUID == null || !cookieStr.contains(existingUUID)) {
cm.setCookie(Settings.COOKIE_DOMAIN, cookieStr);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// CookieSyncManager is deprecated in API 21 Lollipop
CookieSyncManager.createInstance(context);
CookieSyncManager csm = CookieSyncManager.getInstance();
if (csm == null) {
LogUtil.i(Settings.TAG, "Unable to find a CookieSyncManager");
return;
}
csm.sync();
} else {
cm.flush();
}
}
}
}
}
}
} catch (IllegalStateException ise) {
} catch (Exception e) {
}
}
示例15: setSign
import android.webkit.CookieManager; //导入方法依赖的package包/类
public static void setSign(String sign) {
CookieManager instance = CookieManager.getInstance();
instance.setAcceptCookie(true);
instance.setCookie(".qidian.com", "QDSign=" + sign);
}