Example SMS receiver
import inbox, appuifw, e32
def message_received(msg_id): box = inbox.Inbox()
appuifw.note(u"New message: %s" % box.content(msg_id)) app_lock.signal()
box = inbox.Inbox() box.bind(message_received)
print "Waiting for new SMS messages.." app_lock = e32.Ao_lock() app_lock.wait() print "Message handled!"
The Inbox object's bind() function binds a callback function to an event that is generated by an incoming message. In this example, the function message_received() is called when a new message arrives.
The callback function takes one parameter, namely the ID of the incoming message, msg_id. Based on this ID, the message contents, or any other attribute, can be retrieved from the SMS inbox, as we saw above.
The program should not execute from start to finish at once. Instead, it should wait for an event to occur. This time the event is not generated by the user directly, but by an incoming SMS message. Waiting is handled in the familiar manner, using the Ao_lock object.
When a new message arrives, the function message_received () is called. It opens a popup note that shows the contents of the newly arrived message. Then the Ao_lock is released and the program finishes with the message 'Message handled!'. The only way to terminate this program properly is to send an SMS message to your phone.
Post a comment