Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;

public class Main {
    public static String getCookieValue(Context context, String url, String key) {
        CookieSyncManager csm = CookieSyncManager.createInstance(context);
        CookieManager cookieManager = CookieManager.getInstance();
        csm.sync();
        String cookieStr = cookieManager.getCookie(url);
        System.out.println("========cookied:" + cookieStr);
        String[] strs = cookieStr.split(";");
        String value = null;
        for (String string : strs) {
            if (string.trim().startsWith(key)) {
                value = string.substring(string.indexOf("=") + 1);
                break;
            }
        }
        return value;
    }
}