get Cookie from CookieManager - Android android.webkit

Android examples for android.webkit:CookieManager

Description

get Cookie from CookieManager

Demo Code

import android.webkit.CookieManager;

public class Main {

  public static String getCookie(String siteName, String CookieName) {
    String CookieValue = null;/*from w  w w  .j av a  2s .  co  m*/

    CookieManager cookieManager = CookieManager.getInstance();
    String cookies = cookieManager.getCookie(siteName);
    if (cookies == null) {
      return null;
    }
    String[] temp = cookies.split(";");
    for (String ar1 : temp) {
      if (ar1.contains(CookieName)) {
        String[] temp1 = ar1.split("=");
        CookieValue = temp1[1];
      }
    }
    return CookieValue;
  }

} 

Related Tutorials