Deleting messages stored on SIM card using Symbian C++
Article Metadata
Tested with
Devices(s): Tested on Nokia N95,
Nokia 6210 Navigator,
Nokia 5800 XpressMusic
Nokia 6210 Navigator,
Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
S60 3rd Edition, FP2
S60 5th Edition
Article
Created: User:Nokia Developer KB
(03 Apr 2009)
Last edited: hamishwillee
(01 Aug 2012)
Contents |
Overview
This code example can be used to delete the SMS messages stored in the SIM card.
Preconditions
The class should be derived from MMsvSessionObserver.
MMP file
LIBRARY msgs.lib smcm.lib
Header file
//includes
#include <msvapi.h>
#include <msvids.h>
#include <MTCLREG.h>
#include <smsclnt.h>
#include <smut.h>
#include <SMUTSET.H>
#include <smscmds.h>
//declarations
CMsvSession* iMsvSession;
CSmsClientMtm* iSmsMtm;
TMsvId iSimFolderId;
CClientMtmRegistry* iClientMtmReg;
Source file
void CSmsEngine::ConstructL()
{
iMsvSession = CMsvSession::OpenAsyncL(*this);
iClientMtmReg = CClientMtmRegistry::NewL(*iMsvSession);
iSmsMtm = static_cast<CSmsClientMtm*>(iClientMtmReg->NewMtmL (KUidMsgTypeSMS));
}
This function reads the SMS messages on the SIM and creates a copy of those messages in an invisible folder under the SMS service in the message store. If successful, the iEnumerateFolder member of the operation's progress identifies the invisible folder which contains the messages read from the SIM card.
void CSmsEngine::EnumeratePhoneStore()
{
// Find the service entry
CMsvEntry* serviceEntry = iMsvSession->GetEntryL(KMsvRootIndexEntryId);
CleanupStack::PushL(serviceEntry);
TMsvId serviceId;
TSmsUtilities::ServiceIdL(*serviceEntry, serviceId, KUidMsgTypeSMS);
CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection();
CleanupStack::PushL(selection);
selection->AppendL(serviceId);
TBuf8<1> emp (KNullDesC8);
CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC();
CMsvOperation* operation = iSmsMtm->InvokeAsyncFunctionL(
ESmsMtmCommandEnumeratePhoneStores,
*selection,
emp,
waiter->iStatus);
waiter->Start();
TSmsProgressBuf progressBuf;
progressBuf.Copy(operation->ProgressL());
TSmsProgress progress = progressBuf();
if (!progress.iError)
{
//identify the invisible folder that contains the messages read from the phone store(SIM)
iSimFolderId = progress.iEnumerateFolder;
}
CleanupStack::PopAndDestroy( 2, serviceEntry ); // serviceEntry, selection
DeleteSimMessages();
}
This function actually deletes the specified messages from the SIM card.
void CSmsEngine::DeleteSimMessages()
{
TMsvSelectionOrdering sort;
sort.SetShowInvisibleEntries(ETrue); // To handle invisible entries also
CMsvEntry* root = iMsvSession->GetEntryL( KMsvRootIndexEntryId );
TMsvId iSmsServiceId;
CleanupStack::PushL( root );
TSmsUtilities::ServiceIdL( *root, iSmsServiceId );
CleanupStack::PopAndDestroy( root);
CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection();
selection->AppendL(iSmsServiceId); //The first entry ID in aSelection must be the SMS service ID
CleanupStack::PushL( selection );
CMsvEntry* inboxContext=CMsvEntry::NewL(*iMsvSession,iSimFolderId ,sort);
CleanupStack::PushL(inboxContext);
CMsvEntrySelection* entries = inboxContext->ChildrenL();
CleanupStack::PushL( entries );
TInt count=entries->Count();
while(count)
{
//All following entry IDs in the selection must then represent each message to be deleted
selection->AppendL(entries->At(count-1)); count--;
}
TBuf8<1> emp (KNullDesC8);
CMsvOperationActiveSchedulerWait* waiter = CMsvOperationActiveSchedulerWait::NewLC();
iSmsMtm->InvokeAsyncFunctionL(
ESmsMtmCommandDeleteFromPhoneStore,
*selection,
emp,
waiter->iStatus);
waiter->Start();
CleanupStack::PopAndDestroy(2,inboxContext);
CleanupStack::PopAndDestroy(selection);
}
Related article: SMS operations using Symbian C++


(no comments yet)