4

I have an app where my min API is 16, and I want to evaluate some javascript on a web view and when I have

mWebView.evaluateJavascript("(function()...)");

I get a compile error saying this is only available in API 19 and higher, so how can I evaluate javascript in a web view for the API below 19, I have but above code in a if statement for API 19 and above, but how can I do this in API below 19?

Thanks for the help

tim blue
  • 138
  • 2
  • 14

1 Answers1

3

Before API 19, you have to use WebView.loadUrl() with the javaScript protocol to evaluate JavaScript within the currently loaded page:

String javaScript = // Some JavaScript code here

if (Build.VERSION.SDK_INT >= 19) {
    mWebView.evaluateJavascript(javaScript, null);
} else {
    mWebView.loadUrl("javascript:" + javaScript);
}
Alex Forcier
  • 111
  • 6