Java Code Examples for com.tencent.smtt.sdk.CookieManager#setCookie()

The following examples show how to use com.tencent.smtt.sdk.CookieManager#setCookie() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CookieUtils.java    From AndroidHybridLib with Apache License 2.0 6 votes vote down vote up
private static void synCookies(Context context, WebView webView, String domain, Map<String, String> cookieMap) {
    if (cookieMap == null || TextUtils.isEmpty(domain)) {
        return;
    }
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    for (Map.Entry<String, String> entry : cookieMap.entrySet()) {
        String cookie = entry.getKey() + "=" + entry.getValue();
        cookieManager.setCookie(domain, cookie);
    }
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.setAcceptThirdPartyCookies(webView, true);
        cookieManager.flush();
    } else {
        CookieSyncManager.createInstance(context);
        CookieSyncManager.getInstance().sync();
    }
}
 
Example 2
Source File: WebkitCookieUtils.java    From YCWebView with Apache License 2.0 6 votes vote down vote up
/**
 * 同步cookie
 * 建议调用webView.loadUrl(url)之前一句调用此方法就可以给WebView设置Cookie
 * @param url                   地址
 * @param cookieList            需要添加的Cookie值,以键值对的方式:key=value
 */
public static void syncCookie(Context context , String url, ArrayList<String> cookieList) {
    //初始化
    CookieSyncManager.createInstance(context);
    //获取对象
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    //移除
    cookieManager.removeSessionCookie();
    //添加cookie操作
    if (cookieList != null && cookieList.size() > 0) {
        for (String cookie : cookieList) {
            cookieManager.setCookie(url, cookie);
        }
    }
    String cookies = cookieManager.getCookie(url);
    X5LogUtils.d("WebkitCookieUtils-------"+cookies);
    flush();
}
 
Example 3
Source File: CrazyDailySonicRuntime.java    From CrazyDaily with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: AgentWebX5Config.java    From AgentWebX5 with Apache License 2.0 5 votes vote down vote up
public static void syncCookie(String url, String cookies) {

        CookieManager mCookieManager = CookieManager.getInstance();
        if (mCookieManager != null) {
            mCookieManager.setCookie(url, cookies);
            toSyncCookies();
        }
    }
 
Example 5
Source File: WebkitCookieUtils.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
/**
 * 移除指定url关联的所有cookie
 * @param url                           url链接
 */
public static void remove(String url) {
    CookieManager cm = CookieManager.getInstance();
    for (String cookie : cm.getCookie(url).split("; ")) {
        cm.setCookie(url, cookie.split("=")[0] + "=");
    }
    flush();
}