| ID | ... | Creation date | January 22, 2009 |
| Platform | S60 2nd Edition, S60 3rd Edition | Devices | All (S60 2nd and 3rd Edition) |
| Category | Python | Subcategory | Messaging |
| Keywords (APIs, classes, methods, functions): inbox |
Conventionally, the PyS60 code snippet below is used to listen and read incoming SMS constantly.
import inbox, appwuifw, 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)
app_lock = e32.Ao_lock()
app_lock.wait()
print "Message handled"
The above code works well on when run as a script. However, when the same script is converted to a SIS file and then executed, the application crashes. On using one of the Python debugging techniques, it is found to have thrown a MemoryError.
If you have a workaround or a proposed solution for this issue, please feel free to edit this article to add the proposed solution.
The implementation (see below) listens to EMsvEntriesCreated, and then reports that message has arrived. However, at this point the message is not yet fully initialized. One has to wait that EMsvEntriesChanged arrives. This might be reason why people are using "logs.sms(mode='in')[0]" to read the message, I think it works by accident because there is longer delay (here is code clip, it demonstrates another problem but you get the idea: http://discussion.forum.nokia.com/forum/showthread.php?t=140607).
It should be done like this: http://wiki.forum.nokia.com/index.php/CS001416_-_Listening_for_incoming_SMS_messages
Note that this solution might work too: http://wiki.forum.nokia.com/index.php/SMS_Receiver I don't understand why it works, unless the "CMsvEntry* parentEntry" magic has some kind of side-effect not seen on code (note that that variable is not used anywhere).
void CInboxAdapter::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
{
TInt i;
switch(aEvent) {
// New entries only
case EMsvEntriesCreated:
{
if (iCallBackSet) {
// Messages that are created in Inbox
TMsvId* parent;
parent = static_cast<TMsvId*>(aArg2);
// XXX is this needed for Outbox etc.?
// Check the parent folder to be global inbox
if(*parent != KMsvGlobalInBoxIndexEntryId)
return;
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
for(i = 0; i < entries->Count(); i++) {
iErrorState = iCallMe.NewInboxEntryCreated(static_cast<TInt>(entries->At(i)));
}
}
break;
}
default:
break;
}
}
No related wiki articles found