Session cookies in Cordova do not function properly on devices running the Android Lollipop operating system

I recently created a mobile app using Cordova/Phonegap for Android that relies on session cookies to authenticate users with third party websites. The app sends an AJAX post request (using jQuery) and the cookies are automatically set.

However, after updating my smartphone to Android Lollipop 5.0 and upgrading the app libraries to API level 21, I noticed that the cookies stopped functioning properly. What could have caused this change in behavior?

Answer №1

After searching tirelessly online for a solution, I stumbled upon an insightful article that perfectly addresses the issue. I wanted to share it here in hopes that it will benefit other Stack Overflow users.

The root of the problem lies within Android's new policy on third-party cookies (https://developer.android.com/about/versions/android-5.0-changes.html#BehaviorWebView), which now blocks them by default.

The fix involves adding a few lines of code to the main activity:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    super.init();

    // Enabling third party cookies for Android Lollipop
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        WebView webView = (WebView)super.appView;
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptThirdPartyCookies(webView,true);
    }

    super.loadUrl(Config.getStartUrl());
}

For further details, you can find the complete article at this link:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a 500 internal server error while accessing the web server

Anyone out there able to assist? My web service seems to be throwing an error. Receiving a 500 Internal Server Error and 304 Not Modified message The requested XML data is not displaying the body content as expected. var soapMessage ='<soap:E ...

Tap to reveal additional information with the power of Jquery and ajax

I have a question regarding the popup slide functionality. I would like to achieve the following: Currently, I am using the following code to display post details upon clicking: function getPostDetails(id){ var infoBox = document.getElementById("in ...

Is AJAX not submitting properly?

Here is the code snippet that I am working with: var just = $("#just").val(); var id = $("#id").val(); $.ajax({ type: "POST", url: "cod_ajax/just.php", data: "id="+id+"&just="+just, cache: false, success:function(e){ aler ...

Utilizing PHP Variables in Ajax Calls: Transferring Data between JS and PHP

I've been struggling to grasp how to pass information from PHP to JavaScript and vice versa. I've spent an entire night trying to figure this out and would really appreciate it if someone could help me understand how to send two variables to an a ...

What sets Fetch apart from ajax and XMLHttpRequest that makes it impressively faster?

Over the past few days, I have been working on optimizing a client table for a project. The table contains over 10k clients, and as a result, it was taking a long time to load. The front-end team had implemented pagination, filters, and reordering, which ...

Is it possible to transfer data from javascript to php through ajax?

I am attempting to extract the data speedMbps from my JavaScript code using Ajax to send the data to my PHP script, but unfortunately, I am not receiving any output. My experience with Ajax is limited to implementing auto-completion feature. <script sr ...

Revamp the HTML page by automatically refreshing labels upon every Get request

My HTML webpage requires real-time updates for one or more labels. To achieve this, I have incorporated CSS and JS animations into the design. Currently, I am utilizing Flask to handle all the calls. I face a challenge where I need to consistently update ...

The notify.js fails to display notifications in the event of an error

Why am I not receiving any error notifications even when there is an error message in the response object? $.ajax(settings).done(function (response) { if ( "error_message" in response ) { console.log(response); $.notify(" ...

Unobtrusive-Ajax: The Perfect Solution for Passing Parameters in Form.Net Core

I have the following HTML form: <form method="post" data-ajax="true" data-ajax-method="post" asp-action="Requests" asp- controller="Home"> <select id="Records" class="form-c ...

Obsidian Gemstone Adorned with Pearl-Colored Query Symbol

In my code snippet, I am utilizing this: $("#myDiv").load("getTweet.php?tweet_id="+tweet_id+"&yes="+yes+"&no="+no); This call fetches a tweet, but instead of single quotation marks, I see black diamonds with white question marks. I attempted usi ...

Tips for verifying an alphanumeric email address

I need to create an email validation script that allows only alphanumeric characters. <script type = "text/javascript"> function checkField(email) { if (/[^0-9a-bA-B\s]/gi.test(email.value)) { alert ("Only alphanumeric characters and spaces are ...

Using AJAX to Capture PHP Error Responses

I have implemented a form where users can upload profile pictures and see live validation feedback without refreshing the page. I am currently using AJAX for this functionality, but it seems that the requests are not reaching the PHP file. Also, after subm ...

Show a PDF document on the webpage by making an ajax request in a C# MVC application

Using ItextSharp, I am creating a Pdf from html and trying to show a preview of the Pdf on the screen for the user to interact with. Although the Pdf generation is correct, I am struggling to display it on the screen. Here is the Ajax call: function Pre ...

Is the Ajax component updating before the actionListener is activated?

My current setup involves using PrimeFaces <p:dialog> to open a popup HTML page and a <p:commandButton> to close it: When the Ok button is pressed, this is what happens: <p:commandButton id="submitButton" value="OK" actionList ...

"Trouble with making jQuery AJAX calls on Internet Explorer versions 8 and 9

I've been searching for the answer to this problem without any luck. I have a page with jquery ajax calls to an API service. It works well in Chrome, Safari, Firefox, and IE 10, but fails in IE 9 and 8. Here is the code: $.ajax({ ...

"Concealing Querystrings in Node.js and AJAX: A Step-by-Step

I want to create a simple login form using the ajax Post method. However, I am having issues with the querystring still appearing in the URL. Can anyone help me resolve this issue? Thank you for any assistance! [ https://i.stack.imgur.com/R76O4.png http ...

Error message: "Asynchronous task"

Recently, I developed an app with a feature that allows users to log in by verifying their information against a database before redirecting them to the dashboard screen. This functionality was flawless until I started encountering unexpected errors, and I ...

Extracting information from within Ajax's Jsonp

How can I retrieve data from the Ajax function(result)? Why isn't this app working? Please assist me. function star(a) { var res; $.ajax({ url: 'https://api-metrica.yandex.com/analytics/v3/data/ga?end-date=today&ids=ga%3A35 ...

Laravel and jQuery: Seamlessly Uploading Images with AJAX

I have been facing issues while trying to upload photos in Laravel using jQuery AJAX. I keep encountering an error message: The photo must meet the following criteria: - The photo must be an image. - The photo must be a file of type: jpeg, png, jpg, gif, ...

Having difficulty retrieving the necessary information for manipulating the DOM using Express, Ajax, and Axios

When working on DOM manipulation based on AJAX calls, I've encountered an issue where the response is being displayed on my page instead of in the console.log output. This makes it difficult for me to view the data and determine what needs to be inser ...