Skip to content

Instantly share code, notes, and snippets.

@mfdeveloper
Created February 8, 2019 10:18
Show Gist options
  • Select an option

  • Save mfdeveloper/c84911bb180990507798909e685267f9 to your computer and use it in GitHub Desktop.

Select an option

Save mfdeveloper/c84911bb180990507798909e685267f9 to your computer and use it in GitHub Desktop.
public class AndroidWebview extends CordovaWebView {
/**
* Use webview.sendJavascript is deprecated in latest cordova-android
* Insteadof, pass a JS callback like a success function in cordova.exec()
* cordova plugin JS Bridge, and execute a callbackContext.sendPluginResult(result);
* in Java.
*
* Use this, only if you wish call JS from Java webview/cordova app in old
* Android versions
*
* @see http://d.hatena.ne.jp/yohpapa/20130819/1376947942
* @see https://github.com/ionic-team/ionic-plugin-keyboard/pull/40/files
*/
@Deprecated
@TargetApi(Build.VERSION_CODES.KITKAT)
private void sendJavascript(final String javascript) {
webView.getView().post(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
webView.sendJavascript(javascript);
} else {
webView.loadUrl("javascript:" + javascript);
}
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment