1

I'm working on an android app. I'm able to receive cookies but cannot set to cookiemanager using cookiemanager.setcookie(url,string). When I check with cookiemanager.getcookies(url) I get null.

I've tried answers in stack overflow but couldn't get it working. Any ideas would be thankful.

 PersistentCookieStore myCookieStore = ReferenceHolder.getCookieStore();
    List<Cookie> cookies = myCookieStore.getCookies();
    final CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(getActivity());
    final CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.removeSessionCookie();
    if (! cookies.isEmpty()){

        //sync all the cookies in the httpclient with the webview by generating cookie string
        for (Cookie cookie : cookies){
            Cookie sessionInfo = cookie;

            String cookieString = sessionInfo.getName() + "=" + sessionInfo.getValue() + "; domain=" + sessionInfo.getDomain();

            cookieManager.setCookie(ReferenceHolder.BASE_URL, cookieString);


            cookieSyncManager.sync();
        }
        cookieSyncManager.sync();

        System.out.println("COOKIEMAN" + cookieManager.getCookie(ReferenceHolder.BASE_URL));


    }

0 Answers0