0

API creating and save data in a cookie. It works well on the browser. But that cookie is not saved in the android app. Always show a blank array. Anybody know about this? Do android developer has to add any library to save cookie? or it is API side problem.

Harman Cheema
  • 152
  • 1
  • 3
  • 11

2 Answers2

1

You can try this.

/**
 * Checks the response headers for session cookie and saves it if it
 * finds it.
 * 
 * @param headers
 * Response Headers.
 */
public void checkSessionCookie(Map<String, String> headers)
{
    // Config.SET_COOKIE_KEY = "Set-Cookie"
    if (headers.containsKey(Config.SET_COOKIE_KEY) && headers.get(Config.SET_COOKIE_KEY).startsWith(Config.SESSION_COOKIE))
    {
        String cookie = headers.get(Config.SET_COOKIE_KEY);
        if (cookie.length() > 0)
        {
            String[] splitCookie = cookie.split(";");
            String[] splitSessionId = splitCookie[0].split("=");
            cookie = splitSessionId[1];
            // Now here set cookie to your Preference file.
        }
    }
}
Andy Developer
  • 3,071
  • 1
  • 19
  • 39
0

kindly refer,

#How to store data locally in an Android app!

among this options, you can use #Shared Preferences and store user information and access it through out the application.

Radhey
  • 2,139
  • 2
  • 24
  • 42