Running the test program
By now, your Android device is ready to run your PHP scripts— just start Menu and launch SL4A. TKHrH yRu ZLOO find D nuPEHr RI dHPR sFrLSWs SrRYLdHd by PFA, as you can see in Figure 1. Let’s run hello_world. php— just tap it, and then the pencil icon to edit the code, which is shown below: <?php require_once(“Android.php”); $droid = new Android(); $name = $droid -> dialogGetInput(“Hi!”, “What is your name?”); $droid -> makeToast(‘Hello, ’ . $name[‘result’]);
As getInput is depreciated by Android, and will cause an error, you must use dialogGetInput instead. Once done, save and run the code. The result is shown in Figures 2 and 3. As you run the code, you will see a FIX ME error message (Figure 3 top) that reads:
FIX ME! implement getprotobyname() bionic/libc/stubs.c:378
This occurs because the bionic (Android libc) lacks getprotobyname. However, it does not affect the output of your script. When you pack your PHP script into an apk fiOH, it gets removed. For further writing of your own scripts, you can refer to the SL4A API reference at http://code.google. com/p/android-scripting/wiki/ApiReference.
SL4A with PFA opens up Android development to the next level for Web developers, with definitely better programming opportunities while offering users more flexible and interactive applications. So to all developers, happy coding!
References
[1] code.google.com/p/android-scripting/ [2] www.phpforandroid.net
By: Yatharth A Khatri
The author is a FOSS lover who enjoys working on all types of FOSS projects. He is currently doing research on human-computer interaction and is an Android developer too. You can reach him regarding any software issues at yatharth01@gmail.com.