I finally bit the bullet this weekend, and puchased a T-Mobile G2 Touch. I wanted the phone for the Android OS, and it hasn’t disappointed. One of the biggest draws for me is the Android Scripting Environment, which lets you write small apps in Python, Lua, Perl, Ruby and Bash, using an embedded editor and terminal. I can’t describe how cool it is to be able to code on the train, without my laptop. So far, I’ve played around with the Python API, and it really is fantastic - dirt simple to use, and easy enough to extend with external modules. Beautiful Soup comes pre-packaged, but you can recompile the python interpreter with any pure python modules.
The ASE also comes with bindings for a couple of external libraries - Barcode Scanning from ZXing, and text-to-speech using eyes-free. You can also launch ASE scripts from Locale
My first foray into scripting for Android is an attempt to make my music purchasing habits more independent, and avoid RIAA-affiliated artists at all costs. Using RIAA Radar and Amazon Web Services, you can scan a CD barcode and find out whether the album is affiliated with the RIAA.

App on home screen

Scanning a barcode


Looking up ASIN codes from Amazon, and cross-checking against RIAA Radar


Result! You get a notification straight away, and an entry in your notifications in case you want to check several items.
You can download the source for this app here. It requires ASE installed, as well as BarcodeScanner. You will also need an AWS account.
The code itself is pretty simple. The main body of the script is this:
However, the Android barcode scanner returns an EAN-13 barcode, while the RIAA Radar search only uses ASINs. To convert between the two, we use the AWS Product Search API to find an identification number for the product. The algorithm is defined by Amazon, and is a bit lengthy - you can read about it here. The code is below (put together with a lot of help from this post):
The script took me about a day of on-and-off work, and was great fun to write - I’m seriously considering trying some “real” Android dev work. Hopefully this will be of use to some people, and maybe of interest to a lot.