Android Javascript WebView

I have an application where my min API is 16 and I want to evaluate some javascript in webview and when I have

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

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

thanks for the help

+4
source share
1 answer

Before API 19, you should use WebView.loadUrl()a protocol javaScriptto evaluate JavaScript on the page you load:

String javaScript = // Some JavaScript code here

if (Build.VERSION.SDK_INT >= 19) {
    mWebView.evaluateJavascript(javaScript, null);
} else {
    mWebView.loadUrl("javascript:" + javaScript);
}
+3
source

All Articles