×
Namespaces

Variants
Actions
Revision as of 13:37, 28 June 2012 by hamishwillee (Talk | contribs)

Archived:Receiving SMS in PySymbian (Known Issue)

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.


Article Metadata
Tested with
Devices(s): All (S60 2nd and 3rd Edition) 
CompatibilityArticle
Keywords: inbox
Created: croozeus (22 Jan 2009)
Last edited: hamishwillee (28 Jun 2012)

Description

Conventionally, the PySymbian 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 PySymbian 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://www.developer.nokia.com/Community/Discussion/showthread.php?140607-SMS-Problem).

It should be done like this: Listening for incoming SMS messages using Symbian C++

Note that this solution might work too: 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;
}
}
67 page views in the last 30 days.