You Are Here:

Community: Wiki

This page was last modified on 8 September 2009, at 16:57.

SMS Receiver

From Forum Nokia Wiki

Reviewer Approved   

CSMSReceiver example illustrates how you can wait incoming SMS message and extract information from them as soon as they arrive into the inbox. After constructing the iSession inside the ConstructL()-function, the HandleSessionEventL()-function will be called by the OS to notify your class on CMsvSession events.

As shown in the example, inside this function only EMsvEntriesCreated and EMsvEntriesMoved are checked which after the code checks if the event happened for the inbox, which after the HandleEntryL()-function is used to handle individual SMS messages. You could use all functions defined for the CBaseMtm to extract information of the message (and you could also cast the CBaseMtm to CSmsClientMtm for SMS specific functionality), with this example only the body of the message is forwarded to the callback class.

SMS_Receiver.cpp

CSMSReceiver* CSMSReceiver::NewL(MSMSRecCallBack& aObserver)
{
CSMSReceiver* self = new(ELeave)CSMSReceiver(aObserver);
self->ConstructL();
return self;
}
 
CSMSReceiver::CSMSReceiver(MSMSRecCallBack& aObserver):iObserver(aObserver)
{
}
 
CSMSReceiver::~CSMSReceiver()
{
delete iMtmRegistry;
iMtmRegistry = NULL;
 
delete iSession;
iSession = NULL;
}
 
void CSMSReceiver::ConstructL(void)
{
iSession = CMsvSession::OpenSyncL(*this);
iMtmRegistry = CClientMtmRegistry::NewL(*iSession);
}
 
 
void CSMSReceiver::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
{
switch (aEvent)
{
case EMsvEntriesChanged:
{
 
}
break;
case EMsvEntriesCreated:
case EMsvEntriesMoved:
{
TMsvId* entryId;
entryId = static_cast<TMsvId*>(aArg2); // entry id from the session event
 
if ( *entryId == KMsvGlobalInBoxIndexEntryId ) // new entry has been created in Inbox folder
{
TMsvSelectionOrdering sort;
sort.SetShowInvisibleEntries(EFalse); // we dont want to handle the invisible entries
// Take a handle to the Inbox entry
CMsvEntry* parentEntry = CMsvEntry::NewL(*iSession, KMsvGlobalInBoxIndexEntryId, sort);
CleanupStack::PushL(parentEntry);
 
CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);
if(entries)
{
//Process each created entry, one at a time.
for(TInt i = 0; i < entries->Count(); i++)
{
HandleEntryL(entries->At(i));
}
}
 
CleanupStack::PopAndDestroy(1); // parentEntry
}
}
break;
case EMsvCloseSession:
iSession->CloseMessageServer();
break;
default:
// All other events are ignored
break;
}
}
 
void CSMSReceiver::HandleEntryL(TMsvId& aEntId)
{
CMsvEntry* entry = iSession->GetEntryL(aEntId);
CleanupStack::PushL(entry);
 
if(entry->Entry().iMtm == KUidMsgTypeSMS)
{
CBaseMtm* SmsMtm = iMtmRegistry->NewMtmL(KUidMsgTypeSMS);
if(SmsMtm)
{
CleanupStack::Pop(1);//entry
CleanupStack::PushL(SmsMtm);
SmsMtm->SetCurrentEntryL(entry);
SmsMtm->LoadMessageL();
 
HBufC* BodyBuffer = HBufC::NewLC(SmsMtm->Body().DocumentLength());
TPtr BodyPoint(BodyBuffer->Des());
 
SmsMtm->Body().Extract(BodyPoint,0,SmsMtm->Body().DocumentLength());
 
iObserver.GotSMSMessageL(*BodyBuffer);
 
CleanupStack::PopAndDestroy(2);//SmsMtm,BodyBuffer
}
else
{
CleanupStack::PopAndDestroy(1);//entry
}
}
else
{
CleanupStack::PopAndDestroy(1);//entry
}
}

SMS_Receiver.h

class MSMSRecCallBack 
{
public:
virtual void GotSMSMessageL(const TDesC& aMessage) = 0;
};
 
 
class CSMSReceiver : public CBase, MMsvSessionObserver
{
 
public:
static CSMSReceiver* NewL(MSMSRecCallBack& aObserver);
~CSMSReceiver();
protected:
CSMSReceiver(MSMSRecCallBack& aObserver);
void ConstructL(void);
void HandleSessionEventL(TMsvSessionEvent aEvent, TAny *aArg1, TAny *aArg2, TAny *aArg3);
private:
void HandleEntryL(TMsvId& aEntId);
private:
MSMSRecCallBack& iObserver;
CMsvSession* iSession;
CClientMtmRegistry* iMtmRegistry;
};

If you are looking for a full example application for this functionality, you could have a look into an example for monitoring and deleting log entries for SMS messages, especially for Delivery reports is also illustrated in SMS DeliveryReport Deleting Example.

Related Links:

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: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fCreateE5fE4cocalE5fSMSX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxCreateE20E4cocalE20SMSE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZmessagingQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZsmsQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxmessagingX qfnZuserE5ftagQSxsmsX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx3E2E0000X