Saturday, October 10, 2009

Python scripting in Android

Android Scripting Environment (ASE) allow Python script to be run in Android.

Before you can edit and run Python program, you have to Add Interpreter of Python.

Start Android Emulator and ASE installed in the previous article, android-scripting: Android Scripting Environment.

Press MENU key, and select Add Interpreter.

Select Add Interpreter>Python 2.6.2
Wait it to be downloaded and extracted.

Press MENU key again, and select Add Script.


Select Python 2.6.2.


Type the name in the upper box; eg. HelloAndroidPython.py.
Type your Python codes in the lower box. Every Python come with the codes:

import android

droid = android.Android()

It's the android module, which is needed in every Python script that interacts with the available Android APIs.

Add the code below:

droid.makeToast("Hello Android! in Python")



Press MENU and click Save & Run.


Lets see the result:


That's my first Python script in Android:)

------------------------------------------------------------------
For more details of the Python Android API, refer to:
PythonAndroidAPI - A description of the Android API available to Python scripts.

No comments:

Post a Comment