Reputation: 1386
When I load my https url into webview in android, I got the error in logcat like below
E/chromium: [ERROR:ssl_client_socket_impl.cc(1141)] handshake failed; returned -1, SSL error code 1, net_error -101
Due to this CSS and JS is not loaded into webview properly.
I have gone through the this link. But when I load the same URL at second time it's working properly. I am using android 5.0.
Please some help me out from this issue.
Upvotes: 14
Views: 20314
Reputation: 131
Here is the full solution for WebView.
private void loadWebView(String myUrl) {
WebView webView = findViewById(R.id.webView);
ProgressDialog progressdialog = new ProgressDialog(StartModelTest.this);
progressdialog.setMessage("Please wait...");
progressdialog.setCanceledOnTouchOutside(false);
/* JS start*/
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setJavaScriptCanOpenWindowsAutomatically(true);
/* JS start*/
Log.d("TAG", "loadWebView: "+myUrl);
webView.loadUrl(myUrl);
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (!progressdialog.isShowing()) {
Log.d("TAG", "Started: ");
progressdialog.show();
}
}
public void onPageFinished(WebView view, String url) {
if (progressdialog.isShowing()) {
progressdialog.dismiss();
Log.d("TAG", "Finished: ");
}
//Log.d("TAG", "onPageFinished Bool: " + url.contains("home"));
if (url.contains(Util.CLOSING_TAG)) {
finish();
}
}
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
if (progressdialog.isShowing()) {
progressdialog.dismiss();
Log.d("TAG", "Err: ");
}
}
});
}
Upvotes: 1
Reputation: 501
Same error was happened for me and I solved this way. please have a look.
webViewClient = object : WebViewClient() {
override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
showSSLErrorDialog(handler)
}
}
//and the error handler dialog is below
private fun showSSLErrorDialog(handler: SslErrorHandler?) {
val builder = AlertDialog.Builder(this@MainActivity)
builder.setTitle("APP NAME")
builder.setMessage("SOME THING WRONG")
builder.setPositiveButton("YES"){dialog, which ->
// Do something when user press the positive button
handler?.proceed()
//do some other things
}
builder.setNegativeButton("No"){dialog,which ->
handler?.cancel()
//do some other things
}
val dialog: AlertDialog = builder.create()
dialog.show()
}
hope it will help
Upvotes: 0
Reputation: 620
use
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
in your set webview client method
Upvotes: 9