6

It is possible to achieve this currently in Android? I only can find deprecated questions about old methods (CookieSynchManager) which not seems to work for this actually.

It is possible to achieve it? I can't find anything also on the Android Developers' Guide.

halfer
  • 19,824
  • 17
  • 99
  • 186
NullPointerException
  • 36,107
  • 79
  • 222
  • 382

2 Answers2

9

Having the same problem...I solved reading the doc here:

https://developer.android.com/reference/android/webkit/CookieSyncManager

For future readers: to force the Cookie sync process you can manually call the flush() method of CookieManager

I personally put in webview the following code:

public class MyWebViewClient extends WebViewClient {

    public void onPageFinished(WebView view, String url) {
      CookieManager.getInstance().setAcceptCookie(true);
      CookieManager.getInstance().acceptCookie();
      CookieManager.getInstance().flush();
    }
}
Edoardo Vignati
  • 433
  • 5
  • 14
  • 1
    After looking at numerous other answers that didn't work for me, this was the one that finally did. Thanks! – Chris Feb 01 '23 at 22:23
0

Since CookieSynchManager is deprecated, CookieManager.getInstance() is the CookieManager instance for your entire application. Hence, you enable it by

CookieManager.getInstance().setAcceptCookie(true)

setAcceptCookie(boolean accept);

Sets whether the application's WebView instances should send and accept cookies.

https://developer.android.com/reference/android/webkit/CookieManager.html

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77