Resources – Computer Programming

Resources

Tutorials & Books

When to use Python?

What exactly can you do with Python? Here are Python’s 3 main applications.

Who uses Python?

Sample Code / Projects

Tools

 

If you’re just looking to access some native features of your phone, then you can do this with a library called sl4a – or Python Android Scripting Layer. This will let us do things like showing dialogs, reading sensors and even accessing the camera.

The following line will open up your camera and save a photo:

import sl4a

droid = sl4a.Android()
droid.cameraInteractiveCapturePicture(“/sdcard/qpython.jpg”)

Or how about opening up a web page? We can do this simply by saying:

from android import Android

droid = Android()
droid.webViewShow(“https://www.androidauthority.com”)

Kivy and creating APKs

If you want to go further then you’ll need to use Kivy. Kivy basically blows the doors wide open by letting us create fully functional Android apps with multi-touch, graphics and more. And this is also how you can turn your Python scripts into APKs that you can install directly on your Android device or even distribute via the Play Store.

Sample:

from kivy.app import App
from kivy.uix.button import Button

class HelloWorld(App):
 def build(self):
  btn = Button(text='Hello World')
 return btn

HelloWorld().run()

You can develop through Kivy on Windows but if you want to create APKs then I recommend using Linux instead. The problem is that creating APKs from Python scripts is still a long-winded and complex process on Windows and involves installing multiple libraries, the Android NDK, setting paths etc. It is complicated to the point of being nigh impossible. Fortunately, a tool exists that can handle all of the heavy lifting for you which is called ‘Buildozer’.

Tips and Tutorials

Learning / Exploring Daily: My initial 2o days streak