BeanShell Integration

BeanShell is a small, free, and embeddable Java source code interpreter with object scripting language features. BeanShell executes dynamically scripts written in standard Java syntax. In addition, the Java syntax is extended with common scripting conveniences such as loose types, commands, and method closures like those in JavaScript.

FLX has a simple integration to use BeanShell within visual FLX code. The integration is described below. Lets execute the following Java code that finds out whether the phone is connected to a Wifi or a mobile network:

import android.content.Context; 

status = "Not Connected";

ConnectivityManager manager = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo[] networkInfo = manager.getAllNetworkInfo();
for (NetworkInfo netInfo : networkInfo) {
    if (netInfo.getTypeName().equalsIgnoreCase("WIFI")) {
        if (netInfo.isConnected()) {
            status = "Wifi Connected";
    else if (netInfo.getTypeName().equalsIgnoreCase("MOBILE")) {
        if (netInfo.isConnected()) {
            status = "Mobile Data Connected");

We will use two variables: activity and status to move data between FLX and BeanShell:

  1. An instance of Activity is obtained and the reference to it is stored to variable activity. We need to pass a reference to an Activity (or a Context) to BeanShell script because it uses a Context.
  2. Function getActivity (part of Android API) is used to obtain the instance of Activity.
  3. Variable status is used to return the connectivity status string from BeanShell script.
  4. Function interpret is invoked to interpret the given BeanShell script. The function also takes all the variables to be exposed to BeanShell as parameter. In here we expose two variables: activity and status.
  5. BeanShell script is stored into BeanShellScript form object because it has a dedicated script editor (see the next image). But the script can be also given as a plain String. Note that in FLX it is also possible to store the script to text file and read it from there (see File API).
  6. Variable activity is exposed to BeanShell.
  7. Variable status is exposed to BeanShell.
  8. In this example, the String content of the variable status that is manipulated by the BeanShell script is simply printed to FLX Console.

BeanShell Script Editor

FLX provides a simple editor with syntax highlighting for editing BeanShell scripts. Alternatively the executed script can be read from a file using the File API.

  1. Java variable status refers to the FLX variable status.
  2. Variable activity provides the needed Context object.
  3. Variable status is assigned to “Wifi connected”
  4. Variable status is assigned to “Mobile Data Connected”. And what ever is assigned to variable status the value is accessible in FLX.