Android in the development process, often requires the use of WebView to load some pages H5, but sometimes when the page is loaded failures occur, how to resolve today to discuss the next page to load blank question:
Problems caused when loading an HTTPS page
Under normal circumstances, through the WebView loadUrl (String url), you can load the page smoothly. However, when the load via SSL encrypted HTTPS page, if this page's security certificate can not be authenticated, WebView will appear as a blank page.
- Solution:
to accept the credentials of all sites by onReceivedSslError overridden method WebViewClient, ignoring SSL errors.
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
super.onReceivedSslError(view, handler, error);
}
Https page displaying picture resources fail
After Android 5.0, WebView default does not allow mixed use Http Https +, so when Url is Https, the picture is Http resources, resulting in page failed to load. Need to set the MixedContentMode
attribute allows Https + Http mix.
WebSettings wetSettings = webView.getSettings();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
wetSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
H5 pages using DOM storage API results in page loading issues
DOM storage is provided by a standard interface to HTML5, mainly key-value pairs locally, after the page has finished loading the data can be manipulated by JavaScript store, but Android is not turned on by default this feature, causes H5 page failed to load, error log:
[INFO:CONSOLE(186)] "Uncaught TypeError: Cannot read property 'getItem' of null"
[INFO:CONSOLE(1)] "Error:Uncaught TypeError: Cannot read property 'getItem' of null
[INFO:CONSOLE(1)] "Error:Uncaught TypeError: Cannot read property 'activeIndex' of undefined
- Solution:
turn on DOM Storage functionality by setting WebSettings
settings.setDomStorageEnabled(true);