Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 09:10, 23 January 2008.

SMS Receiver

From Forum Nokia Wiki

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 Discussions
Thread Thread Starter Forum Replies Last Post
Can I "stamp" a message with a date and extract it in the reply message DionDK PC Suite API and PC Connectivity SDK 2 2006-02-07 04:09
How can Nokia 30 send and receive Chinese SMS? hengxu2002 Nokia M2M 1 1970-01-01 02:00
Send SMS of Chinese characters in Unicode eddyau General Messaging 1 2003-02-06 07:16
Location API with N73 italomatos Mobile Java General 2 2008-04-02 20:20
help me start a21120060 General Symbian C++ 7 2007-08-24 15:29
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZmessagingQ
     qfnZtopicQUqfnTopicZsmsQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX