0

I want load a third party url (http://domain1.com) on my andoird app using a WebView. This url has a iframe with other domain (http://domain2.com) that has a video player. The page load successfully, but when play the video this not load (when device's api level is < 21), and the android studio console show the next message: Blocked a frame with origin "http://domain2.com" from accessing a frame with origin "http://www.domain1.com" protocols, domains, and ports must match. When device's api level is >= 21 works fine.

WebView's code:

WebView myWebView = (WebView) view.findViewById(R.id.webView);

myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
myWebView.getSettings().setAllowFileAccessFromFileURLs(true);

myWebView.setWebChromeClient(new WebChromeClient());

myWebView.loadUrl(urlWin);

if (Build.VERSION.SDK_INT >= 21) {
    myWebView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE );
} else {
    // Code for Build.VERSION.SDK_INT < 21
}

How do I enable webview's mixed content on api level < 21?

The url is: http://www.winsports.co/liga-aguila-2017-i/multimedia/galeria-compactos/repasa-aqui-los-goles-del-triunfo-de-cali-sobre-junior-72384

victorpacheco3107
  • 822
  • 3
  • 10
  • 32

1 Answers1

-1

Quote from developer.android.com:

Used with setMixedContentMode(int) In this mode, the WebView will attempt to be compatible with the approach of a modern web browser with regard to mixed content. Some insecure content may be allowed to be loaded by a secure origin and other types of content will be blocked. The types of content are allowed or blocked may change release to release and are not explicitly defined. This mode is intended to be used by apps that are not in control of the content that they render but desire to operate in a reasonably secure environment. For highest security, apps are recommended to use MIXED_CONTENT_NEVER_ALLOW.

Code sample:

webView .getSettings() .setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);

Mr. B.
  • 8,041
  • 14
  • 67
  • 117
Saad Bilal
  • 1,767
  • 1
  • 17
  • 31