如何在收件箱创建短信

大家在做Socket拦截短信的时候,不满足拦截条件的短信需要自己把该短信创建到收件箱中,一些朋友遇到这样的问题:在收件箱创建的短信,不是不能回复,就是“信息详情”显示的内容不正确。下面是的一段测试代码,可以正确的在收件箱创建短信,共享出来供大家参考。

// Author: Liguopeng & Chenxiaotian
// aAddr[in]: addresser number
// aContent[in]: sms content
void CSmsMonitorEngine::CreateNewMessageL(const TDesC& aAddr, const TDesC& aContent)
{
const TInt LEN = 12;
 
//================================================================
// 新的代码
//================================================================
iSmsMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId); //test!
 
TMsvEntry newIndexEntry;
newIndexEntry.iDate.HomeTime();
// 短信还未创建完成
newIndexEntry.SetInPreparation(ETrue);
// This is an SMS message
newIndexEntry.iMtm = KUidMsgTypeSMS;
newIndexEntry.iType = KUidMsvMessageEntry;
 
newIndexEntry.iDetails.Set(aAddr);
newIndexEntry.iDescription.Set(aContent.Left(LEN));
 
newIndexEntry.SetSendingState(KMsvSendStateNotApplicable);
newIndexEntry.SetUnread(ETrue);
newIndexEntry.SetNew(ETrue);
 
//in 3rd edition crashes here if capabilities are wrong
newIndexEntry.iServiceId = iSmsMtm->ServiceId();
 
//pID = (TInt*)&newIndexEntry;
//*(pID+2) = 0x120021;
iSmsMtm->Entry().CreateL(newIndexEntry);
 
TMsvId smsId = newIndexEntry.Id();
iSmsMtm->SwitchCurrentEntryL(smsId);
iSmsMtm->Entry().ChangeL(newIndexEntry);
iSmsMtm->SaveMessageL();
 
/*--------------------------------------------
// 重写 header
//------------------------------------------*/
CRichText* richText = CRichText::NewL(CEikonEnv::Static()->SystemParaFormatLayerL(), CEikonEnv::Static()->SystemCharFormatLayerL());
CleanupStack::PushL(richText);
richText->InsertL(0, aContent);
 
CSmsHeader* mySmsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver,*richText);
CleanupStack::PushL(mySmsHeader);
 
CMsvEntry* tmpEntry = iMsvSession->GetEntryL(newIndexEntry.Id());
CleanupStack::PushL(tmpEntry);
if ( tmpEntry->HasStoreL() )
{
mySmsHeader->SetFromAddressL(aAddr);
 
CMsvStore* store = tmpEntry->EditStoreL();
CleanupStack::PushL(store);
 
// 设置短信的创建时间,在msventry里面设置的无效
CSmsDeliver& deliver = mySmsHeader->Deliver();
TTime nowTime;
nowTime.HomeTime();
deliver.SetServiceCenterTimeStamp(nowTime);
 
mySmsHeader->StoreL(*store);
store->StoreBodyTextL(*richText);
 
store->CommitL();
CleanupStack::PopAndDestroy(store);
}
 
// 不能save,否则不是缺主题,就是缺正文
// iSmsMtm->SaveMessageL();
 
TMsvEntry tttEntry = iSmsMtm->Entry().Entry();
// 创建完成
tttEntry.SetInPreparation(EFalse);
// 不设置只读,在收件箱列表处浏览没有回复选项
tttEntry.SetReadOnly(ETrue);
 
iSmsMtm->Entry().ChangeL(tttEntry);
CleanupStack::PopAndDestroy(3, richText); // tmpEntry, mySmsHeader, richText
 
//delete iSmsMtm;
//iSmsMtm = NULL;
//delete iMtmRegistry;
//iMtmRegistry = NULL;
//delete iMsvSession;
//iMsvSession = NULL;
 
return;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值