Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

How to enable cookies in android webview?

how do i enable cookies in a webview?

i tried to use

CookieManager.getInstance().setAcceptCookie(true);

just before calling WebView.loadUrl() and it doesnt work as i get a html page error from a website saying cookies need to be enabled.

What i dont understand is how does cookieManager know which webview to enable cookies?

say if i had a 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?

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

Thanks

question from:https://stackoverflow.com/questions/17230757/how-to-enable-cookies-in-android-webview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...