SL4A - Utilities using Python Facades

Email-based Applications

Email based applications are one of the most common utilities available in a mobile device. One can use the sendEmail API call available through the SL4A Android facade.

This function takes three parameters −

  • to_address − a comma-separated list of recipients.

  • title − represents the title of the email message.

  • message − represents the message to be sent.

import android,datetime,smtplib 
from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText 

droid = android.Android() 
serv = ’’ 
port = 587 
mailto = ’chris’ 
mailfrom = ’charley’ 
pass = ’pass@123’ 

msg = MIMEMultipart() 
msg[‘Subject’] = ’Tes Mail’ 
msg[‘To’] = mailto 
msg[‘From’] = mailfrom 

body = ’This is a test mail!!’ 

smtpCon = smtplib.SMTP(serv,port) 

The python library that have used to build the email program is smtplib. In addition, we have used the email library. This library contains a number of helper functions allowing us to construct our message in the correct form. The mimetypes library helps with the encoding of our message.

Wifi Scanner

The following code lists all available Wi-Fi access spots −

import android, time 

def main(): 
   global droid 
   droid = android.Android() 
while not droid.wifiStartScan().result: 
networks = {} 

while not networks: 
   for ap in in droid.wifiGetScanResults().result: 
      networks[ap[‘bssid’]] = ap.copy() 
   droid.dialogCreateAlert(‘Access Points’) 
   droid.dialogSetItems([‘%(ssid)s,%(level)s,%(capabilities)s’ % 
      ap for ap in networks.values() ]) 

if __name__=’__main__’: 

Call Logs

The code for call logs is given below.

import android 
droid = android.Android() 
mylog = droid.getConstants("android.provider.Calllog$Calls").result 
calls = droid.queryContent(mylog["CONTENT_URI"],["name","number","duration"]).result 

for c in calls: 
   print c
Kickstart Your Career

Get certified by completing the course

Get Started