josemmo josemmo - 1 year ago 154
Ajax Question

Cordova session cookies don't work on Android Lollipop

I develop a Cordova/Phonegap app for Android which uses session cookies to login to third party websites.
For this, I do an AJAX post request (with jQuery) and then cookies are set automatically.

But, when I updated my smartphone to Android Lollipop 5.0 and also the app libraries to API level 21, cookies stopped working. What has changed?

Answer Source

After hours spent looking on the Internet for a working solution, I came across an article that explains the issue really well, so I am posting it here because I thought it will be useful to other Stack Overflow users.

Basically, the problem lies on the new Android third party cookies policy (, which blocks them by default.

The solutions is to add a few lines of code to the main activity:

public void onCreate(Bundle savedInstanceState)

    // Allow third party cookies for Android Lollipop
        WebView webView = (WebView)super.appView;
        CookieManager cookieManager = CookieManager.getInstance();


For more information, I put a link to the full article here:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download