Android WebView Mixed Content cannot display picture resolution

Source: Internet
Author: User

Turn from: http://blog.csdn.net/crazy_zihao/article/details/51557425 Preface

When using WebView to load an HTTPS resource file, if the authentication certificate is not recognized by Android, there will be a failure to load the corresponding resource problem successfully. So, we have to deal with this situation in response.

Resolve Step 1. Enable mixed content

In Android5.0, WebView has made some changes, if your system target API is more than 21:

  • Mixed content and third-party cookies are prohibited by default. You can use Setmixedcontentmode () and setacceptthirdpartycookies () to enable them individually.
  • The system can now intelligently select the portion of the HTML document to draw. This new feature can reduce memory footprint and improve performance. To render the entire HTML document at once, you can call this method Enableslowwholedocumentdraw ()
  • If your app's target API is below 21: The system allows mixed content and third-party cookies, and always renders the entire HTML document at once.
    Add the following code to the class that uses WebView:
  • [HTML] view plain copy print?
    1. Android 5.0 above default does not support mixed Content
    2. if (Build.VERSION.SDK_INT >= build.version_codes. LOLLIPOP) {
    3. Webview.getsettings (). Setmixedcontentmode (
    4. Websettings.mixed_content_compatibility_mode);
    5. }
2. Set WebView to accept certificates for all websites

In the case that the certificate is not accepted by Android, we can fix it by setting the Onreceivedsslerror method of rewriting webviewclient to accept the certificate of all the websites, the code is as follows:

[HTML]View PlainCopyprint?
  1. Webview.setwebviewclient (New Webviewclient () {
  2. @Override
  3. public void Onreceivedsslerror (WebView view,
  4. Sslerrorhandler handler, sslerror error) {
  5. TODO auto-generated Method Stub
  6. Handler.cancel ();//Android Default processing mode
  7. Handler.proceed ();//Accept certificates for all websites
  8. Handlemessage (Message msg);//Other processing
  9. }
  10. });

Note: When overriding WebViewClient the onReceivedSslError method, be aware that the method must be removed onReceivedSslError super.onReceivedSslError(view, handler, error); , otherwise the setting is not valid.

Android WebView Mixed Content cannot display picture resolution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.