TSS001332
S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition
下列代码演示了如何删除SIM卡上的短信。
我们需要从MMsvSessionObserver派生自己的类
MMP
LIBRARY msgs.lib smcm.lib
头文件
//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;
源文件
void CSmsEngine::ConstructL() { iMsvSession = CMsvSession::OpenAsyncL(*this); iClientMtmReg = CClientMtmRegistry::NewL(*iMsvSession); iSmsMtm = static_cast<CSmsClientMtm*>(iClientMtmReg->NewMtmL (KUidMsgTypeSMS)); }
这个函数读取了SIM的消息,然后在信息存储中SMS服务下生成一个不可见的目录用来存储这些信息的拷贝。如果成功后,那么iEnumerateFolder成员函数就会识别包含有这些SIM卡信息的隐藏目录。
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(); }
下面这个函数删除了SIM卡的制定信息内容
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); }