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.

1
  • 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. Commented Dec 2, 2009 at 16:12

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't think addJavascriptInterface() will return a String value
addJavascriptInterface() lets Javascript code call Java code, and Javascript should be able to pass a String parameter to said Java code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.