如何删除存储在SIM卡上的信息

 

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);
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值