如何在android webview中启用cookies? [英] How to enable cookies in android webview?

查看:47
本文介绍了如何在android webview中启用cookies?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在网页视图中启用 cookie?

How do I enable cookies in a webview?

我尝试使用

CookieManager.getInstance().setAcceptCookie(true);

就在调用 WebView.loadUrl() 之前,它不起作用,因为我从网站收到一个 HTML 页面错误,说需要启用 cookie.

just before calling WebView.loadUrl() and it doesn't work as I get an HTML page error from a website saying cookies need to be enabled.

cookieManager 如何知道哪个 webview 启用 cookie?

How does cookieManager know which webview to enable cookies?

假设我有一个屏幕上有两个 webviews 的 Activity,而我只想要其中一个 webviews 启用 cookie,这怎么可能使用 CookieManager?

Say if I had an activity with two webviews in the screen and I only wanted one of those webviews to enable cookies, how is that possible using a CookieManager?

我觉得我错过了一些东西.我找不到像 webView.setCookieManager 或 Cookiemanager.setWebView(webview) 这样的方法.

I feel like I am missing something. I could not find a method like webView.setCookieManager or Cookiemanager.setWebView(webview).

推荐答案

CookieManager.getInstance() 是整个应用程序的 CookieManager 实例.因此,您可以为应用程序中的所有 webviews 启用或禁用 cookie.

CookieManager.getInstance() is the CookieManager instance for your entire application. Hence, you enable or disable cookies for all the webviews in your application.

通常,如果您的 webview 已经初始化,它应该可以工作:http://developer.android.com/reference/android/webkit/CookieManager.html#getInstance()

Normally it should work if your webview is already initialized: http://developer.android.com/reference/android/webkit/CookieManager.html#getInstance()

也许您在初始化 webview 之前调用了 CookieManager.getInstance().setAcceptCookie(true);,这就是问题所在?

Maybe you call CookieManager.getInstance().setAcceptCookie(true); before you initialize your webview and this is the problem?

这篇关于如何在android webview中启用cookies?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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