Loading webview appears blank

1. Huawei mobile phones and other loading webview appear blank
solution:

Loading SSL web pages in WebView is normal and not difficult. But if there is a problem with the certificate of the SSL page to be loaded, such as expired, incorrect information, the issuing authority is not trusted, etc., WebView will refuse to load the page. The browser on the PC will pop up a certificate error dialog box, asking you if you want to ignore the error and continue browsing. In fact, this can be done in WebView to achieve the page with the problem loading the certificate.

WebView webview = (WebView) findViewById(R.id.webview); 
webview.setWebViewClient(new WebViewClient() { 
@Override 
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

    // *** NEVER DO THIS!!! ***
    // super.onReceivedSslError(view, handler, error);

    // let's ignore ssl error
    handler.cancel();
}


Simply overload the WebViewClient's onReceivedSslError() function like this and execute handler.proceed() in it to ignore the SSL certificate error and continue loading the page.

The thing to note here is, never call super.onReceivedSslError(). This is because the onReceivedSslError() function of WebViewClient contains a handler.cancel() (see the source code, which means to stop loading, so if super.onReceivedSslError() is called, the result is that it cannot be loaded when it is accessed for the first time. It can be loaded after the second time (don't know why), and a segfault of libc may also occur:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324648599&siteId=291194637