How to properly handle cookies in Android

Question:

I am implementing a request to the server that sets the PHPSESID in the cookie, I do it like this:

        response = httpClient.execute(httpPost, responseHandler);

        List<Cookie> cookiesReq = httpClient.getCookieStore().getCookies();
        if (!cookiesReq.isEmpty()) {
            Log.d(TAG + " : test cookie", url);
            String cookieStr = "";
            for (Cookie cookie : cookiesReq) {
                cookieStr += " " + cookie.getName() + "=" + cookie.getValue() + ";";
                Log.d(TAG, cookieStr);
            }
            if (!cookieStr.equals("")) {
                setCookiesPreference(cookieStr);
            }
        }

Those. I manually need to serve cookies for each request, is there a way to do it like in the browser, they were installed by themselves without my supervision?

Answer:

Look towards CookieSyncManager

Scroll to Top