当前位置: 首页>>代码示例>>Java>>正文


Java CookieManager.setCookie方法代码示例

本文整理汇总了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();
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:24,代码来源:Utility.java

示例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();
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:25,代码来源:Utility.java

示例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();
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:19,代码来源:BaseWebView.java

示例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();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:27,代码来源:HttpTask.java

示例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();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:a.java

示例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();
        }
    }
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:9,代码来源:AgentWebConfig.java

示例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);
}
 
开发者ID:MarcusMa,项目名称:MyCreditCardDemo,代码行数:9,代码来源:CmbChinaLoginActivity.java

示例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();
    }
}
 
开发者ID:quickhybrid,项目名称:quickhybrid-android,代码行数:20,代码来源:QuickUtil.java

示例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();

}
 
开发者ID:smartbeng,项目名称:PaoMovie,代码行数:9,代码来源:WebViewFun.java

示例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);
}
 
开发者ID:liying2008,项目名称:Simpler,代码行数:17,代码来源:CookieKeeper.java

示例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();
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:39,代码来源:PortalActivity.java

示例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();
}
 
开发者ID:kamisakihideyoshi,项目名称:TaipeiTechRefined,代码行数:39,代码来源:PortalFragment.java

示例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;
}
 
开发者ID:Justson,项目名称:AgentWeb,代码行数:12,代码来源:DefaultSonicRuntimeImpl.java

示例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) {
    }
}
 
开发者ID:prebid,项目名称:prebid-mobile-android,代码行数:49,代码来源:ServerConnector.java

示例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);
}
 
开发者ID:AoEiuV020,项目名称:QidianLite,代码行数:6,代码来源:Utils.java


注:本文中的android.webkit.CookieManager.setCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。