You Are Here:

Community: Wiki


KIP001278 - Receiving SMS in PyS60

From Forum Nokia Wiki



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

Description

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.

Problem

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;
}
}

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fKIP001278E5fE2dE5fE52eceivingE5fSMSE5finE5fPyS60X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZKnowledgeBaseContentQ qdcZtypeQUqfntypeZKnownIssueQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZKnowledgeBaseContentQ qfnZtypeQUqfntypeZKnownIssueQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxpythonX qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZKnowledgeBaseContentQ qrdfZtypeQUqfntypeZKnownIssueQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx1E2E0000X