user2763424
user2763424

Reputation: 69

Android cookies using phonegap

I have developed a phonegap application that has a user login page with a text box for username/password, a check box for "remember my info", and a submit button.

Pretty standard.

When I open it in Firefox, the cookie works fine and my login data is remembered when the box is checked.

However, when using the android emulator, my cookie is not saved, despite "navigator.cookieEnabled" returning true when printed on the emulator for debugging.

I can post the relevant code if needed but my question is more general:

How can you store cookies in android programming using the web based languages that PhoneGap supports? Is it similar to normal web page javascript cookies? Is there a method other than "navigator.cookieEnabled" that will return whether or not cookies are enabled for the android device?

Thanks.

Upvotes: 1

Views: 2983

Answers (1)

power_scriptor
power_scriptor

Reputation: 3304

For mobile application development HTML5 has new feature for Local Store and Session Store. Same like cookies and session in web development

Try with localStorage option. I worked this way only.

For storing values in local storage i.e stored in browser permanently

window.localStorage.setItem("key", "Value");

For getting values in local storage

window.localStorage.getItem("Key")

For manually remove values for local storage

window.localStorage.removeItem("Key")

If you want to manage session you need to use sessionStorage option.

For storing values in session storage i.e values destroyed once mobile apps closed

window.sessionStorage.setItem("key", "Value");

For getting values in session storage

window.sessionStorage.getItem("Key")

For manually remove values for session storage

window.sessionStorage.removeItem("Key")

Upvotes: 4

Related Questions