(Transfer) WebView loading webpage does not display pictures solution

Original address: https://blog.csdn.net/u013320868/article/details/52837671

 

For everyone, WebView must be familiar, because we often use it in daily development. So I won't be verbose about some of its basic usages here, and go directly to the topic.

The problem I encountered was that the picture was not displayed when using WebView to load the webpage (my mobile phone system is 5.1.1). At that time, when this problem occurred, I took it for granted that there was something missing for WebView. Then Baidu:

        mWebview.getSettings().setJavaScriptEnabled(true);//Enable js
        mWebview.getSettings().setBlockNetworkImage(false);//Solve the picture is not displayed


Then I checked my code, and these two sentences were obviously added, what the hell is this. I also added some other settings later, but it still didn't work. Could it be that there is something wrong with my access path, so I randomly found a webpage with pictures and loaded it with WebView. Oh, I wiped it, and the pictures showed nothing wrong. It seems that there is really a problem with my access path, but everything else is displayed fine, why is the picture not displayed. I traced the breakpoint and copied the access path to see. I rely on the original access path to be https. So I pointed the finger at https. Simply put, https is the secure version of http, which adds an ssl layer to http. When using the https protocol, you need to apply for a security certificate. I wonder if there is a problem with the security certificate. Looking back, if there is a problem with the security certificate, the page should be blank. Where did the problem lie, so I copied the path of the webpage to the browser and opened it, and then checked the source code of the webpage, and found that the reference of the picture is from http. Could the problem be here? As expected:


So I added this sentence when setting up WebView, and the problem was solved. Even if the system below 5.0 does not add this sentence, the picture can still be displayed normally, and the personal test is effective.

Guess you like

Origin blog.csdn.net/duyiqun/article/details/103176760