English 中文(简体)
SL4A - Utilities using Python Facades
  • 时间:2024-09-08

SL4A - Utipties using Python Facades


Previous Page Next Page  

Email-based Apppcations

Email based apppcations are one of the most common utipties 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 pst of recipients.

    title − represents the title of the email message.

    message − represents the message to be sent.

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

droid = android.Android() 
serv = ’smtp.gmail.com’ 
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!!’ 
msg.attach(MIMEText(body,’plain’)) 

smtpCon = smtppb.SMTP(serv,port) 
smtpCon.starttls() 
smtpCon.login(mailfrom,pass) 
smtpSendmail(mailfrom,mailto,msg.as_string()) 
smtpCon.close()

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

Wifi Scanner

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

import android, time 

def main(): 
   global droid 
   droid = android.Android() 
	
while not droid.wifiStartScan().result: 
   time.sleep(0.25) 
	
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,%(capabipties)s’ % 
      ap for ap in networks.values() ]) 
		
droid.dialogSetPositiveButtonText(‘OK’) 
dorid.dialogShow() 

if __name__=’__main__’: 
   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
Advertisements