The method in Android to access the SSL web page where the certificate is in question
- 2020-05-30 21:04:06
- OfStack
The browser on PC will pop up a dialog about whether you should continue browsing despite the error. You can actually do this in WebView to load the page with the certificate in question.
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.proceed();
}
}
Simply reload WebViewClient's onReceivedSslError() function like this and execute handler.proceed () in it to ignore the SSL certificate error and continue loading the page.
The important thing to note here is that you should never call super.onReceivedSslError (). This is because WebViewClient's onReceivedSslError() function contains an handler.cancel () (see source code), which means stop loading, so if super.onReceivedSslError () is called, the result is that it cannot be loaded on the first access, it can be loaded on the second access (for some reason), and libc segment error may occur:
A/libc: Fatal signal 11 (SIGSEGV) at 0x00000010 (code=1)