Android: How to store cookies?

前端 未结 5 881
挽巷
挽巷 2020-12-02 10:06

In my Android app, each activity is filled with data from an xml file which is somewhere on the web. The website providing these files has a login mechanism, that works with

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 10:51

    Use a CookieSyncManager to store your cookie value. It can persist across application starts.

    Beware of using CookieSyncManager inside of WebViewClient#shouldInterceptRequest on KitKat. It will deadlock.

    EDIT

    CookieSyncManager was deprecated in API 21:

    This class was deprecated in API level 21. The WebView now automatically syncs cookies as necessary. You no longer need to create or use the CookieSyncManager. To manually force a sync you can use the CookieManager method flush() which is a synchronous replacement for sync().

提交回复
热议问题