×
Namespaces

Variants
Actions

如何在收件箱创建短信

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

兼容于
平台:
Symbian

文章
Cxt_programmer 在 17 Jul 2008 创建
最后由 hamishwillee 在 08 May 2013 编辑
  • 测试平台:

S60 2nd Edition

S60 3rd Edition

  • 详细描述

大家在做Socket拦截短信的时候,不满足拦截条件的短信需要自己把该短信创建到收件箱中,一些朋友遇到这样的问题:在收件箱创建的短信,不是不能回复,就是“信息详情”显示的内容不正确。下面是我以前的一段测试代码,可以正确的在收件箱创建短信,共享出来供大家参考,在这里特别感谢诺基亚论坛中ID为qxiaoyuan的朋友在大量S60 2nd、3rd真机上所做的测试

// 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;
}
This page was last modified on 8 May 2013, at 03:01.
54 page views in the last 30 days.