How do I enable cookies in a webview?
I tried to use
CookieManager.getInstance().setAcceptCookie(true);
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.
How does cookieManager know which webview to enable cookies?
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?
I feel like I am missing something. I could not find a method like webView.setCookieManager or Cookiemanager.setWebView(webview).
How do I enable cookies in a webview? CookieManager. getInstance(). setAcceptCookie(true);
Webview properly, APP has to share cookies with Ms. Webview in the way she prefers, that is through the WebKit CookieManager.
This example demonstrate about How to enable app cache for webview in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
You should consider that
CookieManager.getInstance().setAcceptCookie(true);
doesn't work from lollipop(API21) and above. You should check and use appropriate function for that case:
if (android.os.Build.VERSION.SDK_INT >= 21) { CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, true); } else { CookieManager.getInstance().setAcceptCookie(true); }
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With