Monday, April 21, 2008

SMS Operations in Symbian 3rd edition

Some notes of experience (most likely for my own future reference) to accompany the Wiki entry on SMS Operations. In particular, this is useful for those who are new to Symbian. The above link gave example on how to send an SMS, and delete the sent message, but the code (SmsHandler.zip) needs to be a slight tweak to make it work.

Problem Description: Usually applications that sends out SMS messages like to do so discreetly. The example given doesn't delete the SMS sent by your application?

Solution:

1. At the sending of SMS,
Change: need to put the Application UID into the SMS created at CreateMsgL()

2. At the HandleSessionEventL() for the new message to move from "Outbox" to the "Sent" folder,
Change: need to match the Application UID (inserted in step 1) -- highlighted here in the code addition for HandleSessionEventL()

case EMsvEntriesMoved:
{
// Entry id is obtained from the session event arguments.
TMsvId* entryId = STATIC_CAST( TMsvId*, aArg2 );

// We are interested in messages that are moved to Sent Item Folder
if ( *entryId == KMsvSentEntryId )
{
TMsvSelectionOrdering sort;
// to handle also the invisible entries
sort.SetShowInvisibleEntries(ETrue);

CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession, KMsvSentEntryId, sort);
CleanupStack::PushL(parentEntry);

CMsvEntrySelection* entries = parentEntry->ChildrenL();
CleanupStack::PushL(entries);

for(TInt i = 0; i < entries->Count(); i++)
{
// iMtmData3 here must match your application UID, in which case
// variable 'KUidMsgTypeSMS' needs to be renamed accordingly
if( parentEntry->ChildDataL(entries->At(i)).iMtmData3 == KUidMsgTypeSMS.iUid )
{
parentEntry->DeleteL(entries->At(i));
break;
}
}
CleanupStack::PopAndDestroy( entries );
CleanupStack::PopAndDestroy( parentEntry );
}
break;
}
}

NOTE: there was a bug in the example given at the Wiki entry; I've changed this to help all newbies checking out this code.

No comments: