How to Solve Cookie Sync Problems With Android WebView Apps

Workplace with smartphone, laptop, latte and cookies on table

Cookies were originally invented in 1994 by Lou Montulli for Netscape Communications Corporation to provide an easy way for websites to store and access information about visitors. A cookie is a small file that is stored on a user’s computer or mobile device. It can be used to identify a user, store information about them, and keep track of their activity. Cookies are not just used by websites anymore. They are also used by apps, email services, and other types of software. This article aims to cover the basics of what cookies are and why they exist in the first place. On Android WebView apps, cookies are handled by a service called CookieManager.

So, how does CookieManager in Android WebView work?
CookieManager in Android WebView is a cookie management library that provides a centralized interface for managing cookies. To be more specific, CookieManager is a subclass of WebViewClient that handles cookies in Android WebView. It allows the application to control the cookie settings and read the cookies set by a server. The CookieManager class is an extension of WebViewClient, which provides several methods to allow applications to control cookie settings and read the cookies set by the server. It provides three general config settings:

– setAcceptCookies(boolean): enables or disables accepting cookies
– getAcceptCookies(): returns true if accepting cookies
– readCookies(): gets all the stored cookies

The problem: It can happen that the CookieManager does not synchronize all cookies correctly, e.g., if the app was open for less than 30 seconds or if certain one-pager pages use AJAX technologies.

Handle Cookies on Android WebView Applications – let’s get it working!

For a smooth app experience and web app functionality wrapped in your Android app, it’s crucial to make Android WebView apps with WebView work reliably with cookies. Here is how it works:

1. Get WebViewGold for Android.

2. In, set the MANUAL_COOKIE_SYNC variable to true.

3. In the COOKIE_SYNC_TIME variable, you can set how often the cookies should sync with the app in milliseconds (ms).

4. Moreover, in the MANUAL_COOKIE_SYNC_TRIGGERS variable, you can add URL prefixes you want to use the Manual Cookie Sync tool on. If MANUAL_COOKIE_SYNC_TRIGGERS is empty, it will automatically check every page. Example: {“”, “”}

That’s it; enjoy your new WebView Android app with working cookie synchronization!