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.
We wanted Python so we went for Py4A – Python 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.
Here is a list of files that you need to download:
sl4a_r4.apk: The SL4A Frontend
textedit-sl4a.apk: Editor for the scripts
PythonForAndroid_r5.apk: Python Interpreter for SL4A (Or the latest version available)
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.
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.
Here is the Video that Demonstrates all procedures after the Files are Downloaded: