Page 300 -
P. 300
your script on android
Test Python on Android
Return to your emulator’s main screen and find an app called SL4A added to your list
of app icons. Tap this app to display the list of Python scripts preinstalled with Python
for Android. Simplty tap on any script name to execute it:
The “menu”
button.
Be sure to set
the SL4A
rotation mode
to automatic.
Your screen might
switch to landscape by default
the first time you run a script.
To fix this, choose Menu ➝
Take your Android emulator for a spin Preferences, scroll down to
Rotation mode, and set its
Here’s a four-line Python script that you can create to test your installation. value to Automatic.
Let’s call this script mydroidtest.py:
Import the “android”
library and create a new
app object instance. import android
app = android.Android()
msg = "Hello from Head First Python on Android"
Create an appropriate
message and display it on app.makeToast(msg)
screen.
To transfer your script to the emulator, you need to copy it to the emulator’s Issue this command at your terminal
virtual SD card. Another program within the tools folder called adb helps window to transfer your script to
with this: the emulator.
tools/adb push mydroidtest.py /sdcard/sl4a/scripts
Your script should now appear on the list of scripts available to SL4A.
264 Chapter 8