views:

1842

answers:

2

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.

+1  A: 

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
I don't think **addJavascriptInterface()** will return a String value
Tawani
addJavascriptInterface() lets Javascript code call Java code, and Javascript should be able to pass a String parameter to said Java code.
CommonsWare
+3  A: 

Actually, this article Using WebViews on WhyAndroid addresses that same issue.

Tawani