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

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.
{ 0 comments... read them below or add one }
Post a Comment