Android WebView not loading Mixed Content

taeuk

I'm trying to make a app with WebView, but the website is using https, but the content (ex. mp3 file) uses http, so Android Lollipop won't load it because it is "Mixed Content". I tried to use onReceivedSslError handler.proceed();, but it doesn't load anything. Is there a way to fix it? or could I just make all websites loaded use http, so It doesn't show any errors?

user11153

Since Pie (API 29), all non-HTTPS traffic in app is now disabled by default.

If you're targeting API level 26 or above, you must first enable it in the manifest file. Add

android:usesCleartextTraffic="true"

into <application> tag.


Since Lollipop (API 21), WebView blocks all mixed content by default.

To change this behaviour, when you are targeting API level 21 or above, use:

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

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.

In practice this should allow loading of images, videos, music etc. - all content that has low probability of being major security threat, when tampered/replaced by malicious third-party.


Alternatively use (strongly discouraged):

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

In this mode, the WebView will allow a secure origin to load content from any other origin, even if that origin is insecure. This is the least secure mode of operation for the WebView, and where possible apps should not set this mode.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Android webview loading fail in API 21 and above

分類Dev

Blogger API Retrieve specific post issue loading content in WebView

分類Dev

Android webview content sometimes not fit the width

分類Dev

Android flutter's flutter_webview_plugin plugin's webview shows loading indicator and nothing else

分類Dev

Android flutter's flutter_webview_plugin plugin's webview shows loading indicator and nothing else

分類Dev

How to clear Webview content to change the video in Android Oreo

分類Dev

Android WebView

分類Dev

Android WebView

分類Dev

Url not loading in Webview using ViewModel

分類Dev

Ajax content loading issues

分類Dev

DTD define Number of occurrences of elements with mixed content

分類Dev

SVG loading issue in react native WebView (iOS)

分類Dev

Show ProgressBar while loading a url to a WebView

分類Dev

Windows Phone 8.1 webview not loading local files

分類Dev

Android webview slow

分類Dev

getUserMedia Android Webview Ionic

分類Dev

adding ReactJS in android Webview

分類Dev

Xamarin Android Webview Javascript

分類Dev

Android WebView localStorage

分類Dev

Add webview into linearlayout android

分類Dev

Android webview loadData

分類Dev

WebView Methods is not called in android

分類Dev

Webview in Android programming

分類Dev

Enable attachment in WebView android

分類Dev

Android HTML WebView

分類Dev

Android Webview: console is not defined

分類Dev

Android webView touchEvents

分類Dev

Android WebView Jsoup

分類Dev

Xamarin 本机 Webview Android