get Cookie using CookieManager - Android Network

Android examples for Network:Cookie

Description

get Cookie using CookieManager

Demo Code


//package com.java2s;
import android.webkit.CookieManager;

public class Main {
    public static String getCookie(String siteName, String CookieName) {
        String CookieValue = null;

        CookieManager cookieManager = CookieManager.getInstance();
        String cookies = cookieManager.getCookie(siteName);
        if (cookies == null) {
            return null;
        }//from   ww  w  . j a  v  a 2 s.  c o m
        String[] temp = cookies.split(";");
        for (String ar1 : temp) {
            if (ar1.contains(CookieName)) {
                String[] temp1 = ar1.split("=");
                CookieValue = temp1[1];
            }
        }
        return CookieValue;
    }
}

Related Tutorials