當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。