具有https loadUrl的Android WebView显示空白/空白页 [英] Android WebView with https loadUrl shows blank/empty page

查看:593
本文介绍了具有https loadUrl的Android WebView显示空白/空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android 4.3上创建了一个Android WebView应用程序,该应用程序首先打开一个登录页面,然后它应该将我链接到一个https页面,但不是打开https页面,而是显示网页不可用".我试图用Web浏览器打开它,然后首先打开该站点的安全证书不受信任!".并按继续后,页面将打开.

I created an Android WebView app on Android 4.3 which firstly opens a log in page and after that it should link me to a https page, but instead of opening the https page it says "Web page not available". I tried to open the same with the web browser and firstly opens "The site's security certificate is not trusted!" and after pressing to proceed the page opens.

虽然我用过:

    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error)
    {                          
        handler.proceed(); 
    }

WebView仍然不会打开https页面.有什么办法可以在Web视图中打开https页面?你能帮我吗?

the WebView still won't open the https page. Is there any possible way to open the https page in the webview? Could you please help me?

推荐答案

    webView=(WebView)findViewById(R.id.webView);
    WebSettings webSettings=webView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webView.setWebViewClient(new MyWebViewClient());
    webView.loadUrl("your https url here");

    private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        webView.loadUrl(url);
        return true;
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler,
                                   SslError error) {
        super.onReceivedSslError(view, handler, error);
        handler.proceed();
    }
}

这篇关于具有https loadUrl的Android WebView显示空白/空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆