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


Java CookieSyncManager.getInstance方法代码示例

本文整理汇总了Java中android.webkit.CookieSyncManager.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java CookieSyncManager.getInstance方法的具体用法?Java CookieSyncManager.getInstance怎么用?Java CookieSyncManager.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.webkit.CookieSyncManager的用法示例。


在下文中一共展示了CookieSyncManager.getInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addCookie

import android.webkit.CookieSyncManager; //导入方法依赖的package包/类
public void addCookie(Cookie c, boolean addToWebViewCookieManager, boolean sync) {
    if(addToWebViewCookieManager) {
        CookieManager mgr;
        CookieSyncManager syncer;
        try {
            syncer = CookieSyncManager.getInstance();
            mgr = getCookieManager();
        } catch(IllegalStateException ex) {
            syncer = CookieSyncManager.createInstance(this.getContext());
            mgr = getCookieManager();
        }
        java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z");
        format.setTimeZone(TimeZone.getTimeZone("GMT"));
        String cookieString = c.getName()+"="+c.getValue()+
                "; Domain="+c.getDomain()+
                "; Path="+c.getPath()+
                "; "+(c.isSecure()?"Secure;":"")
                +(c.isHttpOnly()?"httpOnly;":"")
                + (c.getExpires() != 0 ? ("Expires="+format.format(new Date(c.getExpires()))+";") : "")
                ;
        mgr.setCookie("http"+
                (c.isSecure()?"s":"")+"://"+
                c.getDomain()+
                c.getPath(), cookieString);
        if(sync) {
            syncer.sync();
        }
    }
    super.addCookie(c);
        
    
    
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:34,代码来源:AndroidImplementation.java

示例2: httpCookieSync

import android.webkit.CookieSyncManager; //导入方法依赖的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

示例3: setAcceptCookie

import android.webkit.CookieSyncManager; //导入方法依赖的package包/类
@Override
public void setAcceptCookie(Context context, boolean accept) {
	CookieSyncManager.getInstance();
	CookieManager.getInstance().setAcceptCookie(accept);
}
 
开发者ID:v7lin,项目名称:Android_Skin_3.x,代码行数:6,代码来源:CookieManagerCompat.java


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