Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute JavaScript on Android?

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 show error of missing classes. Is it possible to execute JS code in Android? Thank you.

like image 636
user1078760 Avatar asked Dec 04 '11 07:12

user1078760


People also ask

How do I run a JavaScript app?

To execute JavaScript in a browser you have two options — either put it inside a script element anywhere inside an HTML document, or put it inside an external JavaScript file (with a . js extension) and then reference that file inside the HTML document using an empty script element with a src attribute.

Can we do JavaScript in phone?

JavaScript frameworks are well-suited to mobile app development, as they can be used across a number of platforms, including iOS, Android, and Windows.

How do I open a JavaScript file on my phone?

For Samsung Mobile Devices: Go to Settings -> About device -> Software info -> Scroll to see 'Build number' -> tap on the screen multiply times until pop up message come up saying 'Developer Mode on'. This will enable new option in your device Settings 'Developer options'.


1 Answers

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.

like image 114
Evgenii Avatar answered Sep 29 '22 11:09

Evgenii