Wednesday, 16 January 2013

Accessing the SMS Inbox


Accessing the SMS Inbox

Let’s start with an example which shows five messages from your SMS
inbox.
Example 14: SMS inbox
import inbox, appuifw
box = inbox.Inbox()
for sms_id in box.sms_messages()[:5]:
msg = box.content(sms_id)
appuifw.note(msg)
Besides the familiar appuifw module, which is needed for showing
notes, we need to import the inbox module that encapsulates access to
the SMS inbox.
All functions related to receiving SMS messages belong to the Inbox
object which is created with the inbox.Inbox() function. To read an
individual SMS message, you need to know its message ID.
The Inbox object’s function sms messages() returns message IDs
for all messages in your phone’s SMS inbox. Since you may be a texting
maniac who keeps thousands of messages in the inbox, this example
shows up to five of them. From the list returned by the sms messages()
function, we slice off the first five items using the slicing operator [:5].
The content() function returns the content of a message given its
message ID. The content, or the actual text of the message, is then shown
in a popup note.

No comments:

Post a Comment