简体   繁体   中英

Android webview how long cookies are saved?

My app saves cookies but deletes them after 2 weeks. I need the data to be stored for a long time. Please help me.

public void getWebview(String myurl) {
    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return super.shouldOverrideUrlLoading(view, url);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            CookieManager.getInstance().setAcceptCookie(true);
            CookieManager.getInstance().acceptCookie();
            CookieManager.getInstance().flush();
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
        }

    });
    webView.loadUrl(myurl);
}

cookies are stored as long as they should, may be even years... but that depend on cookie setting. inspect Set-Cookie: header in your request responses and you will find out how long your cookie should be kept by WebView (I bet "your" site is setting cookie validity for 2 weeks)

some article about mechanic of cookie (and its expiration)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM