8

Given that scripting is not natively supported in Android and wrapping libraries like javax.script.ScriptEngine into your app will make it too large, is it possible to send a javascript string to an invisible WebView and have it evaluate the string and return you the results (another string)?

I want to go this route because I want to save all my scripts to disk so my app can remain small.

Edit

I need Java code to evaluate javascript strings not the other way around. addJavascriptInterface() doesn't help.

Tawani
  • 11,067
  • 20
  • 82
  • 106
  • How is the javascript going to going to see your program in order to act upon it? Just executing scripts in a vacuum isn't going to do much good. – Josh Lee Dec 02 '09 at 16:12

1 Answers1

6

Can it be done? Yes, via addJavascriptInterface() and sending the browser a javascript: URL, akin to a bookmarklet.

A far simpler answer, one that will use much less memory and will execute much faster, is to not use Javascript.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I don't think **addJavascriptInterface()** will return a String value – Tawani Dec 01 '09 at 20:07
  • 4
    addJavascriptInterface() lets Javascript code call Java code, and Javascript should be able to pass a String parameter to said Java code. – CommonsWare Dec 02 '09 at 05:09