I have been facing some problem with Old API versions. Some Links of some websites don't respond as they have preconditions that third party cookies must be enabled for webview. I did some search on topic and found an API :
CookieManager.getInstance().acceptThirdPartyCookies();
It fixes my issue and enables third party cookies but Min API level is 21. I need to support lower API level as low as 15. Is there any way we can perform same operation in lower API.
[Please note that API : CookieManager.getInstance().setAcceptCookie(true); is for enabling cookies and not third party cookies so it does not do the trick...:-(]
I found one answer feel like to share it. In Lower than LOLLIPOP(including LOLLIPOP) Third party cookies are enabled by default. In higher API levels than LOLLIPOP we need to explicitly set third party cookies so I added following if else in my code(Min API 16) :
if(Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
Log.d(AppConstants.TAG,"SDk version above android L so forcibaly enabling ThirdPartyCookies");
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,true);
}
However it shows compile time error. it does not stop build and in higher API levels where we need to forcibly set third party cookies, this code does the trick.
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