Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Listing inbox messages using Symbian C++

From 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}}.

The article is believed to be still valid for the original topic scope.

This code snippet demonstrates how to list SMS messages in the Inbox.

Article Metadata
Code ExampleTested with
Devices(s): Nokia 6220 Classic, Nokia 5800 XpressMusic
Platform(s): S60 3rd Edition, FP2; S60 5th Edition
S60 5th Edition
S60 3rd Edition FP2
Keywords: CMsvSession, CClientMtmRegistry, CSmsClientMtm, CMsvEntry, CMsvEntrySelection, CMsvStore, MMsvSessionObserver, TMsvSelectionOrdering, TMsvId, CRichText, CMsvSession::OpenAsyncL(), CClientMtmRegistry::NewMtmL(), CMsvEntry::ChildrenL(), CSmsClientMtm::SwitchCurrentEntryL(), CMsvSession::GetEntryL(), CMsvEntry::ReadStoreL(), CSmsClientMtm::Body(), CMsvStore::RestoreBodyTextL()
Created: tapla (03 Mar 2009)
Last edited: lpvalente (23 Sep 2014)


MMP file

The following capabilities and libraries are required:

LIBRARY msgs.lib

Header file

#include <msvapi.h>
class CClientMtmRegistry;
class CSmsClientMtm;
class CAppUi : public CAknAppUi, public MMsvSessionObserver
public: // Methods from base classes
* From MMsvSessionObserver

void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1,
TAny* aArg2, TAny* aArg3);
private: // New methods
void ListInboxContentsL();
private: // Data
CMsvSession* iSession;
CClientMtmRegistry* iMtmRegistry;
CSmsClientMtm* iSmsMtm;
// Other methods and data omitted for brevity

Source file

#include <msvapi.h>
#include <msvids.h> // KMsvGlobalInBoxIndexEntryId
#include <mtclreg.h> // CClientMtmRegistry
#include <smsclnt.h> // CSmsClientMtm
#include <smut.h> // KUidMsgTypeSMS
#include <txtrich.h> // CRichText

In the constructor, initialise the member variables:

// Open the session to message server (asynchronous)
iSession = CMsvSession::OpenAsyncL(*this);
// Create an MTM Registry object
iMtmRegistry = CClientMtmRegistry::NewL(*iSession);
// Create an SMS Client MTM object
iSmsMtm = STATIC_CAST(CSmsClientMtm*, iMtmRegistry->NewMtmL(KUidMsgTypeSMS));

In the destructor, free the pointers:

delete iSmsMtm;
delete iMtmRegistry;
delete iSession;
void CAppUi::ListInboxContentsL()
// Access the Inbox
TMsvSelectionOrdering sort;
CMsvEntry* inboxContext = CMsvEntry::NewL(*iSession,
KMsvGlobalInBoxIndexEntryId, sort);
// Get all entries in the Inbox
CMsvEntrySelection* entries = inboxContext->ChildrenL();
TInt messages = entries->Count();
for (TInt i = 0; i < messages; i++)
TMsvId entryID = entries->At(i);
CMsvEntry* entry = iSession->GetEntryL((*entries)[i]);
CMsvStore* inboxStore= entry->ReadStoreL();
if (inboxStore->HasBodyTextL())
// Get the sender's details
TMsvEntry smsEntry = entry->Entry();
HBufC* aText = smsEntry.iDetails.AllocL();
CleanupStack::PopAndDestroy(); // aText
// Get the SMS contents
CRichText& richText= iSmsMtm->Body();
const TInt length = richText.DocumentLength();
HBufC* smsContent = richText.Read(0, length).AllocL();
CleanupStack::PopAndDestroy(); // smsContent
// The SMS contains no text
CleanupStack::PopAndDestroy(2, entry);
CleanupStack::PopAndDestroy(2, entries);
void CAppUi::HandleSessionEventL(TMsvSessionEvent aEvent,
TAny* aArg1, TAny* aArg2,
TAny* /*aArg3*/)
// Not implemented


The application lists the SMS messages in the Inbox on the screen.

Supplementary material

This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful for developers. The version of the Symbian stub application used as a template in this snippet is v1.1.

This page was last modified on 23 September 2014, at 19:56.
134 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.