Skip to content

Instantly share code, notes, and snippets.

@Ansh1234
Created April 26, 2017 12:57
Show Gist options
  • Save Ansh1234/a7bed39fd7ada25920a91a32f1c5bb55 to your computer and use it in GitHub Desktop.
Save Ansh1234/a7bed39fd7ada25920a91a32f1c5bb55 to your computer and use it in GitHub Desktop.
public static void callJavaScriptFunction(final WebView webView, final String script) {
if (webView == null) {
return;
}
webView.post(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.evaluateJavascript(script, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
}
});
} else {
webView.loadUrl("javascript:" + script);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment