-1

I'm currently making an android app. This app will have to execute a script when a certain button is clicked. The problem is, I have no idea how to execute this script. Can somebody please help me? If you could, just give me the basic code needed for this. You could also show me how to execute it in the On clicked switch and case (I may use switch and case. I'm not sure yet). But all I'll really need is the code to execute a script, and, if you don't mind, explain it a little bit. Thanks!

josephoneill
  • 853
  • 2
  • 10
  • 33

1 Answers1

0

The discussion about running a UNIX script can be found here. How to run Unix shell script from Java code?

If its a javascript, you need to load the script engine and run your script in that context. Hope this helps. Am just attaching a script eval that I had written sometime back.

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class OperatorAsVariable
{
    public static void main( String args[] ) throws ScriptException
    {
        String test = "+";
        System.out.println( 1 + test + 2 );
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName( "js" );
        System.out.println( engine.eval( 1 + test + 2 ) );
    }

}
Community
  • 1
  • 1
LPD
  • 2,833
  • 2
  • 29
  • 48