Wednesday, March 16, 2011

Let Android read my SMS

Another I tried on SL4A is to play with their SMS function. So, with the resulting code below:

  1. As usual import library, and create the Android() object
  2. and from the Android object call smsGetMessages, with a required parameter for unread message, True for unread only, false for other wise.
  3. and call the build in android Text To Speech software to read it out, by calling ttsSpeak method.

import android
droid = android.Android()
result = droid.smsGetMessages(True)
for i in result.result:

the result in the output is a list of such dictionary, in python notnion. Since I only want the message so I call it by i['body']

{u'_id': u'59',
u'address': u'Address of sender aka the phone no',
u'body': u'Message Body',
u'date': u'1300254988000',
u'read': u'1'}
the date is the datetime read and the read is 1 is read, and 0 otherwise. The ttsSpeak method is easy to use too, just pass in a string.

Originally I read all messages, and pass to the tts library. Turn out to be a bad idea, because I have no idea how to stop it from speaking once it started....

Thursday, March 03, 2011

My First Day on Android Scripting

I got myself a android phone not that long ago. One reason is, it is pretty amazing piece of hardware. Unlike iphone the SDK is available on major OS, including linux. One of the many stuff I installed is SL4A, Scripting Layer for Android, and the python interpreter for android.

One cool thing SL4A do is, we test the code remotely from a python. The wiki page have a good explanation on how to do this.

One of the first thing I play around via the python interpreter on the laptop

import  android
droid = android.Android()
data = droid.getNetworkOperatorName()
print data.result
The api page have a lot of information, so that is one place that one should look. 
Not much of a program nor a post, but yeah it is a start of something beautiful. I hope