CookieSyncManager is now deprecated, what can I use instead?

后端 未结 3 1777
暗喜
暗喜 2020-12-14 18:36

I\'m using a cookie in my app which works fine in all browsers, but in android device the cookie is not setting as fast as I wanted, it takes some time until cookie is saved

相关标签:
3条回答
  • 2020-12-14 19:14

    Nothing : "The WebView now automatically syncs cookies as necessary. You no longer need to create or use the CookieSyncManager."

    As DarkKnight said, you can test if your app target below API 21 Lollipop (5.0), if not, you don't need anymore CookieSyncManager.

    0 讨论(0)
  • 2020-12-14 19:16

    Simply Just enable javascript And Dom Storage. this helps me to remember my login details in my webview android app. I Didn't use Any CookieManager But Enabling This Do the trick for me.

     webView.getSettings().setJavaScriptEnabled(true);
     webView.getSettings().setDomStorageEnabled(true);
    
    0 讨论(0)
  • 2020-12-14 19:19

    On Lollipop and beyond, the CookieManager singleton works fine by itself. (Refer Link - http://developer.android.com/reference/android/webkit/CookieManager.html) however, prior to Lollipop it also required the use of an additional static method from CookieSyncManager. The code below works for me on all Android versions when setting the cookies on a WebView -

    CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        CookieSyncManager.createInstance(this);
    }
    cookieManager.setAcceptCookie(true);
    
    0 讨论(0)
提交回复
热议问题