I am trying to add JavaScript to read at a specific value on load webView.
These are the properties that I used for mine webView.
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setCacheMode(2);
webView.getSettings().setDomStorageEnabled(true);
webView.clearHistory();
webView.clearCache(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(false);
webView.getSettings().setLoadWithOverviewMode(false);
webView.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
and I embed javacript in my method onPageFInished().
@Override
public void onPageFinished(final WebView view, final String url) {
webView.post(new Runnable() {
@Override
public void run() {
webView.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('input')[0].value+'</head>');");
}
});
super.onPageFinished(view, url);
}
Below is the code MyJavaScriptInterface.
public class MyJavaScriptInterface{
@JavascriptInterface
public void showHTML(String html_data) {
if(html_data.contains("response_code")){
Log.e(TAG, " ======> HTML Data : "+ html_data);
new MakeQueryPayment().execute();
}
}
}
The error I captured from Logcat.
01-08 17:56:43.701 I/chromium(27026): [INFO:CONSOLE(1)] "Uncaught TypeError: window.HTMLOUT.showHTML is not a function", source: (1)
I only encountered this problem on the Samsung Galaxy Tab , model number SM-T550 , Android version 5.0.2 . In the other devices that we have, it works fine. Can anyone help me on this. Thanks in advance.