Android Calling JavaScript functions in WebView
I figured out what the issue was : missing quotes in the testEcho() parameter. This is how I got the call to work:
myWebView.loadUrl("javascript:testEcho('Hello World!')");
From kitkat onwards use evaluateJavascript method instead loadUrl to call the javascript functions like below
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { webView.evaluateJavascript("enable();", null); } else { webView.loadUrl("javascript:enable();"); }
public void run(final String scriptSrc) { webView.post(new Runnable() { @Override public void run() { webView.loadUrl("javascript:" + scriptSrc); } }); }