Get up and running with the Android Scripting Environment. Whip up a Twitter update app in a matter of minutes and tell everyone what sandwich you're eating from within Android!
There are many Android tutorials on the Internet and books in the bookstores showing how to write applications — I know, I’ve read many of them and have even been fortunate enough to have the opportunity to write a few myself. Up until this point, every Android application I have seen has been written in Java with a few of the more intrepid tutorials covering the topic of getting a “C” application to run on Android.
While writing applications in Java and the Android SDK is really pretty easy for a coder with an interest in learning the SDK, there is a bit of a learning curve in getting the tools setup, navigating the SDK and getting your application to run happily on the device. If you are looking to write an application for the Android Market, using the SDK is the way to go.
But what if you are interested in just hacking around a little on the device itself? What if you’re looking for a mobile Internet device that you can program anywhere — even while you are waiting patiently at the doctor’s office?
With the Android Scripting Environment, you can do just that! If you are familiar (or willing to learn) Python, Lua, or BeanShell, you can write applications directly on your Android device — no laptops, no compilers, no kidding. Follow along as we learn about the Android Scripting Environment and create a script in Python to submit entries to your Twitter account.
Android Scripting Environment
The Android Scripting Environment (ASE) installs to your Android device just like any other Android application. You can download the ASE installation file from its project page on googlecode.com. I have the alpha 0.7 version of ASE installed on my development phone.
You can use ASE to write applications much as you would in any Linux environment. Interact with the user, perform calculations, connect to the Internet. You can even access a subset of the Android SDK functionality from the scripting environment such as reading Android’s sensors and launch other applications. This flexibility allows an experienced developer (or script writer) to customize the Android environment without having to go the SDK development route. Scripts can be installed as a Service to be available at all times or be even triggered by the Locales plugin.
Once the ASE application is installed and launched on your Android phone, you will see the “Script Manager” where all activity is initiated.
The ASE installs with a handful of sample scripts which demonstrate basic scripting functionality. Clicking on any of the scripts will start the script in a new terminal window using the appropriate script interpreter engine. The file extension determines which interpreter is launched.
For example, a script with a “.bsh” extension is processed via the BeanShell interpreter. To create a new script, select the menu button and choose “Add”. If you want to enter script commands directly into the interpreter, choose the “Terminal” menu selection. You can choose from each of the supported and installed script interpreters. To edit or delete an existing script, perform a long-click (press and hold) of the selection.
Script Editing Actions
Note that you can also create a shortcut on the home/launch window. This is helpful if you write something useful (of course you will!) and want to be able to launch it quickly. I created a shortcut to my “Twitter Status” script, which is in the script file named ts.py.
Script Editing Actions
It is time to have a look at our script. To test this script, you will require an Android device (or emulator) with internet access. As already mentioned, you can edit scripts directly on the device through the ASE ScriptManager code window, however you may not want to type all of the code directly into your device. Good news — you can simply copy the file to your device as a starting point.
Next: Confessions of a Python Newbie