如何在应用执行之间持久保存webview cookie? [英] How to persist webview cookies between app executions?

查看:105
本文介绍了如何在应用执行之间持久保存webview cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前可以在Android中实现吗?我只能找到有关旧方法(CookieSynchManager)的已过时的问题,实际上似乎不适用于此方法.

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.

有可能实现吗?在android开发人员指南上也找不到任何内容.

It is possible to achieve it? can't find anything also on the android developers guide.

谢谢

推荐答案

有同样的问题...我解决了在这里阅读文档的问题:

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

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

对于将来的读者:要强制执行Cookie同步过程,您可以手动调用CookieManager的flush()方法

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

我个人在webview中添加了以下代码:

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();
    }
}

这篇关于如何在应用执行之间持久保存webview cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆