Scripting Android(SL4A) with Python on LG Optimux P500

We got our first Android Phone LG Optimus P500 with Android 2.2 Version. This phone has 512MB of internal RAM which is good to give a decent performance. We did not limit us to this, we wanted to make some good use of this mobile. So the Idea came that we can try to have a programming environment right int the Android Phone.
We knew that there is a complete development environment available to use PC as the host and develop applications for Android. But we wanted some thing easier. Something that could help us get Python on Mobile.
We found Scripting Layer for Android brings scripting languages to Android. SL4A in short.

Scripting Layer for Android (SL4A) brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface that makes it easy to get things done.
Scripts can be run interactively in a terminal, in the background, or via Locale. Python, Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell are currently supported, and we’re planning to add more. See the SL4A Video Help playlist on YouTube for various demonstrations of SL4A’s features.

We wanted Python so we went for Py4APython for Android.
This is the version of Python that’s built to Run with the SL4A and includes various functionality such as Blue-tooth Encryption etc.

[1]
Here is a list of files that you need to download:
sl4a_r4.apk: The SL4A Frontend
http://android-scripting.googlecode.com/files/sl4a_r4.apk

textedit-sl4a.apk: Editor for the scripts
http://android-scripting.googlecode.com/files/textedit-sl4a.apk

PythonForAndroid_r5.apk: Python Interpreter for SL4A (Or the latest version available)
http://python-for-android.googlecode.com/files/PythonForAndroid_r5.apk

Python Modules:
pyephem-3.7.4.1-py2.6-linux-armv.egg
http://python-for-android.googlecode.com/files/pyephem-3.7.4.1-py2.6-linux-armv.egg

PyBluez-0.19-py2.6-linux-armv.egg
http://python-for-android.googlecode.com/files/PyBluez-0.19-py2.6-linux-armv.egg

pycrypto-2.3-py2.7-linux-armv.egg
http://python-for-android.googlecode.com/files/pycrypto-2.3-py2.7-linux-armv.egg

Now after you have all these files in the Phone in a separate Directory say “/sdcard/Develop/
You are ready to go for the Installation.

[2] 
Steps for Install:
– Install the sl4a_r4.apk File (Make sure you have install from Unknown source option enabled in settings)
– Install the textedit-sl4a.apk and PythonForAndroid_r5.apk
– After this transfer the SL4A and TextEdit applications to SD card from settings
– Open the Python for Android App and click on Install
   (The App would now download the nessary files automatically. So make sure you have your internet connection ON in the mobile)
– After the Extraction is done it would show that the installation has been successful, Now click on Import Modules and sequentially install the modules one after another. (All three of them)
– Exit the Python for Android App and then run the SL4A app to get the SL4A Frontend running.
  (Dont miss this else like in the Video the programs wont run)
– Now go back to Home screen keeping the SL4A running in background – Run the Text Edit App
– Browse the SD Card for “sl4a” folder in which the “scripts” directory contains the “HelloWorld.py
   (should be “/sdcard/sl4a/scripts“)
– Now you can edit the file and save it
Go back to Home screen and Open the SL4A app again. Click the Option button to refresh the files
Single click on the HelloWorld.py shows the activity bar. (this contains the “Terminal Run” or “Edit” Options)
Click on the Terminal icon to Run the Modified HelloWorld.py
– You see a terminal window automatically pop out and then says “Hello World”
– Now you would be prompted to Exit the Terminal so click “Yes” 
That’s It – You have successfully executed your first Python Script on Mobile.

[3]
Here is the Video that Demonstrates all procedures after the Files are Downloaded:
http://www.youtube-nocookie.com/v/jWjV47U0Md8?version=3&hl=en_US

Advertisements

About boseji

Bharteya Anusandhankarta ( Indian Researcher)
This entry was posted in Android, LG Optimux P500, mobile, python, SL4A, software, tutorial. Bookmark the permalink.

2 Responses to Scripting Android(SL4A) with Python on LG Optimux P500

  1. Anonymous says:

    sl4a app could not recognise *.py scripts. how could i execute it? i am using samsung galaxy 3 i5801

  2. Boseji says:

    Hello,
    We have specified the procedure and the order of the installation in the post. Thus if you have installed the Py4A before SL4a it should work. Else you can also install the Interpreter from SL4A. Select the option button on the first screen and then select “Add”. Now select “Interpreter” and select “Python”.
    Let us know if this works.
    Warm Regards,
    Boseji

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s