简体   繁体   中英

Android WebView - Intercept URL loading

I'm trying to determine the successful payment event from the payment portal. You might know this process: you send a 'callback URL' as one of other parameters to the payment website. When the payment is made the website re-directs the browser to your 'callback URL'.

Since this is Android application I specify a custom url with a custom scheme ('myapp://order/123') as a 'callback URL' Then I use the following technique to intercept the re-direct to my 'callback URL' to do some custom action.

mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            LOG.info("Inside shouldOverrideUrlLoading(), url: {}", url);

            if (url.startsWith("myapp://")) {
                onPaymentPerformed();
                return true;
            } else {
                return false;
            }
        }
}

It worked for many months but recently it started failing. I don't know why but probably due to device updates. This method has stopped being called for 'myapp://' url. I've checked the logs and found the following message

I/chromium: [INFO:CONSOLE(2174)] "Mixed Content: The page at 'https://www.liqpay.com/en/checkout/success/xxxx' was loaded over a secure connection, but contains a form which targets an insecure endpoint 'myapp://order/7'. This endpoint should be made available over a secure connection.", source: https://static.liqpay.com/checkout/160922113118/js/index.js (2174)

Then I tried to change 'myapp://order/123' to ' https://order/123 ' but the method shouldOverrideUrlLoading() is also not called for this url, instead I see a standard error message in the webview:

The webpage at https://order/123 could not be loaded because: net::ERR_NAME_NOT_RESOLVED

I found nothing similar to this on Internet, please help

You could subclass the WebClient and override the onReceiveSslError method.

 private class SSLTolerentWebViewClient extends WebViewClient {
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        handler.proceed(); // proceed ignoring ssl error. 
    }
}

See if that works.

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