I am integrating payment gateway in my application using WebView. I want to read the response from HTML content basically it is a JSON object. This is working fine on 6.0 devices. But for 7.0 and 8.0 I am facing issue with JavaScript. I am using the below code.
My Code
vPayment.loadUrl(myurl);
wvPayment.getSettings().setJavaScriptEnabled(true);
wvPayment.getSettings().setDomStorageEnabled(true);
wvPayment.clearCache(true);
wvPayment.clearHistory();
wvPayment.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
wvPayment.addJavascriptInterface(iface, "HTMLOUT");
wvPayment.setWebChromeClient(new WebChromeClient());
wvPayment.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (request.getUrl().toString().contains("mysuuccessurl")) {
try {
String html = URLDecoder.decode(request.getUrl().toString(), "UTF-8").substring(9);
System.out.println("html" + html);
} catch (UnsupportedEncodingException e) {
Log.e("example", "failed to decode source", e);
}
}
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
System.out.println("Start url : " + url);
customProgressDialog.show();
}
@Override
public void onPageFinished(WebView view, String url) {
System.out.println("Finish url : " + url);
if (url.contains(mysuccessurl)) {
wvPayment.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
}
customProgressDialog.dismiss();
}
});
JIFace iface = new JIFace();
class JIFace {
@android.webkit.JavascriptInterface
public void showHTML(String data) {
//want to handle the response here
}
}
}
What is wrong with the above code. What changes needs for this work on 7.0 and above android devices