Android: accept third-party cookies when targeted to SDK>=21
@@ -27,6 +27,8 @@ import android.webkit.WebBackForwardList;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebViewClient;
+import android.webkit.CookieManager;
+
public class GoogleWebView implements IRhoWebView {
private static final String TAG = GoogleWebView.class.getSimpleName();
@@ -85,6 +87,23 @@ public class GoogleWebView implements IRhoWebView {
mWebView.setHorizontalScrollbarOverlay(true);
mWebView.setFocusableInTouchMode(true);
int sdkVersion = Build.VERSION.SDK_INT;
+
+ if ( sdkVersion >= 21 ) {
+ Logger.I(TAG, "Enabling third-party cookies");
+ CookieManager cm = CookieManager.getInstance();
+ try {
+ java.lang.reflect.Method mtdAllow3Party = cm.getClass().getMethod("setAcceptThirdPartyCookies", android.webkit.WebView.class, boolean.class);
+ mtdAllow3Party.invoke(cm,mWebView,true);
+ Logger.I(TAG, "Enabling third-party cookies done");
+ } catch (SecurityException e) {
+ Logger.W(TAG, "Can't allow third-party cookies explicily due to SecurityException");
+ } catch (NoSuchMethodException e) {
+ Logger.W(TAG, "Can't allow third-party cookies explicily due to NoSuchMethodException");
+ } catch ( Exception e ) {
+ Logger.E(TAG, "Can't allow third-party cookies explicily due to exception: " + e.toString() );
+ }
+ }
+
/* if(sdkVersion <19){
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
