Document.cookie does not seem to be working

1,263 views
Skip to first unread message

Steven

unread,
May 15, 2012, 5:25:51 AM5/15/12
to phonegap
Hi all,

I'm fixing a Javascript Phonegap application - targeted for Android 4
platform.

The problem is that document.cookie doesn't seem to be working. Right
after setting up a cookie, I tried to read, but it returned nothing.
Checking using document.cookie.length returned 0.

FYI It works if I compile it for Android 2 platform - it also works in
the browser.

Can anyone explain why?

(I know I can probably try to use localStorage, but I would appreciate
if someone can give an explanation about the situation I am currently
having).

Thanks.














Ignatius Steven

unread,
May 15, 2012, 11:06:20 PM5/15/12
to phonegap
Bump.

Regards,
Steven















--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Colleen Liley

unread,
May 17, 2012, 12:42:26 PM5/17/12
to phonegap
Bump too!

On May 15, 11:06 pm, Ignatius Steven <ignatius.ste...@gmail.com>
wrote:

Kerri Shotts

unread,
Jun 27, 2012, 12:38:13 PM6/27/12
to phon...@googlegroups.com
I wonder if there's a setting on the webview for Android 4 that is disabling cookie support? I'm not well-read enough on the Android APIs so I'm only speculating here. Personally, the better way would be to use localStorage, but since you're asking about cookies specifically, that's my best guess. The Android 2 webview is a different enough beast that it wouldn't surprise me that things that work fine there break on 4.x.

What version of phonegap specifically?

Colleen Liley

unread,
Jun 27, 2012, 1:28:54 PM6/27/12
to phon...@googlegroups.com
You have to make the parent Phonegap project accept local cookies. To do so, You should have a file called youappname.java in your PhoneGap project, probably with this contents or similar:

import android.os.Bundle;
import org.apache.cordova.*;

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
   
super.loadUrl("file:///android_asset/www/index.html");
}
}

Modify it to look like this example:

import android.os.Bundle;
import android.webkit.CookieManager;
import org.apache.cordova.*;

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   
CookieManager.setAcceptFileSchemeCookies(true);
   
super.onCreate(savedInstanceState);
   
super.loadUrl("file:///android_asset/www/index.html");
}
}
Reply all
Reply to author
Forward
0 new messages