CookieSyncManager is now deprecated, what can I use instead?

后端 未结 3 1799
暗喜
暗喜 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: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);
    

提交回复
热议问题