Automating your Android Phone with SL4A
In the first installment of this article we looked at getting Google's Scripting Layer for Android (SL4A) downloaded and installed on your Android phone. We examined the basics of writing scripts using Python and even included a short script to set a few of the profile settings. This time we'll take a look at some of the sample scripts found on the SL4A website and talk about how you might write a script of your own.
The first thing you should do after installing the SL4A application on your phone is to add a shortcut to the scripts folder on one of the home screens. On the HTC EVO you can do this by pressing on an empty space and hold until the Add to Home dialog appears. From here you can add a Widget, App, Shortcut or Folder. Selecting Folder presents a list of available folders and an option to create a New Folder. Selecting the Scripts folder will add a folder icon to the current home screen. Once that's done, you'll have single-click access to any of the scripts stored on your SD card in the sl4a/scripts directory.
It seems as though there is a universal rule when teaching a new programming language that you must create a program to output the phrase "Hello World". SL4A holds to this premise and includes a link to a version of this program on the Wiki Tutorials page. If you take a look at some of the examples on that page, you'll see a number of items with potential uses like Twitter clients, talking weather forecast, a silent mode trigger to set the phone to vibrate during sleeping hours and more. We'll take a look at a few of those samples to help explore the possibilities.
One of the really useful examples in the tutorial list is under the title "How to get your own IP address". This example creates a simple HTTP server on your phone that you can connect to from your host machine. If you have WiFi enabled on the phone and it's on the same network as your host machine, you'll be able to use a web browser to view the files on your SD card. This can come in really handy when you're out and about and you'd like to quickly move a picture from your phone to say your netbook. The source code for this looks like:
from os import chdir
Then you just hit the IP address of your phone from a browser and download images using a right mouse click and 'Save As'.
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: CoreOS, Oracle Enterprise Linux 7 and Ubuntu 14.10
- 5Linux Top 3: Knoppix 7.3, Slacko Puppy 5.7 and PC-BSD 10.0.1