简体   繁体   中英

Loading https via android webview

I'm new to android and in my app, I need to get connection to an https for payment action and here's how my webview currently looks like when I try to make connection.

webview失败

I've looked up on the web for solutions to loading https via overriding onReceivedSslError method to ignore the error and proceed onwards. So, I have done so as the following.

Here's my webview getting its settings:

web = (WebView)findViewById(R.id.web);

// setting WebViewClient
web.setWebViewClient(new WebViewClientClass());
web.getSettings().setDomStorageEnabled(true);
web.getSettings().setJavaScriptEnabled(true);
web.loadUrl(orderSheetUrl);

where orderSheetUrl is the https url to which my payment action takes the user to.

Below is my WebViewClient class:

private class WebViewClientClass extends WebViewClient {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        Log.d("WebView", "onPageStarted " + url);
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        Log.d("WebView", "in shouldOverrideUrlLoading");
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        Log.d("WebView", "onReceivedSslError");
        handler.proceed(); // Ignore SSL certificate errors
    }

    @Override
    public void onPageFinished(WebView view, String url) {
        Log.d("WebView", "onPageFinished " + url);
    }
}

The problem here is then I try to load the link, but find in my log that only the logs for onPageStarted and onPageFinished is being called.

Here's my logs:

12-13 17:06:31.760 8694-8694/? D/WebView: onPageStarted :"https://alpha-bill.payco.com/easyLogin/201512132004116802?inAppYn=Y"
12-13 17:06:31.760 8694-8694/? D/WebView: onPageFinished :"https://alpha-bill.payco.com/easyLogin/201512132004116802?inAppYn=Y"
12-13 17:06:31.790 8694-9927/? E/Adreno-ES20: <check_framebuffer_attachment:854>: Invalid texture format! Returning error!
12-13 17:06:31.790 8694-9927/? E/Adreno-ES20: <check_framebuffer_object_status:1237>: Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!
12-13 17:06:31.800 8694-8694/? W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 8694
12-13 17:06:31.810 8694-8694/? W/cr.BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 8694
12-13 17:06:32.180 8694-8795/? E/Adreno-ES20: <check_framebuffer_attachment:854>: Invalid texture format! Returning error!
12-13 17:06:32.180 8694-8795/? E/Adreno-ES20: <check_framebuffer_object_status:1237>: Framebuffer color attachment incomplete. Returning GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT!

I really don't get why the onReceivedSslError method is not called even when I access a url starting with https, which from my understanding should require a certificate to have an access.

Have I done something wrong with implementing my WebViewClient ? Or is there any other way around this? Thanks in advance for the help.

PS my target API is 23 and minimum is 15.

From the documentation:

Notify the host application that an SSL error occurred while loading a resource.

So why should it be called when there is no error?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM