How to execute JavaScript on Android?

后端 未结 10 1439
迷失自我
迷失自我 2020-11-27 14:38

I have code which uses ScriptEngineManager, ScriptEngine class for executing JavaScript code using Java. But it works fine in Java SE, and doesn\'t work in Android - SDK sh

10条回答
  •  生来不讨喜
    2020-11-27 14:56

    AndroidJSCore is a great one. And here is another little library I wrote for evaluating JavaScript:

    https://github.com/evgenyneu/js-evaluator-for-android

    jsEvaluator.evaluate("function hello(){ return 'Hello world!'; } hello();", new JsCallback() {
      @Override
      public void onResult(final String result) {
        // get result here (optional)
      }
    });
    

    It creates a WebView behind the scenes. Works on Android version 3 and newer.

提交回复
热议问题