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.
Asked
Active
Viewed 6,008 times
0
-
U have to store the cookie in shared preferences and use it for other requests which you want to proceed. By default it won't save – King of Masses Sep 22 '17 at 04:47
-
sharedpreferences is the answer – phpdroid Sep 22 '17 at 04:47
-
Go through with this link https://stackoverflow.com/questions/10704023/storing-and-restoring-cookies-in-android-persistent-cookie-storage – Ankita Sep 22 '17 at 05:00
-
then you save them incorrectly. You need to fix way you save them, that's it. – Vladyslav Matviienko Sep 22 '17 at 05:20
2 Answers
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