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.net.ConnectivityManager;
import android.content.Context;
import android.net.NetworkInfo;
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:

- 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.
- Function getActivity (part of Android API) is used to obtain the instance of Activity.
- Variable status is used to return the connectivity status string from BeanShell script.
- 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.
- 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).
- Variable activity is exposed to BeanShell.
- Variable status is exposed to BeanShell.
- 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.

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