在收件箱创建短信
来源:互联网 发布:java命令编译java文件 编辑:程序博客网 时间:2024/04/29 23:23
http://discussion.forum.nokia.com/forum/showthread.php?t=155087&highlight=%2A%E6%94%B6%E4%BB%B6%E7%AE%B1%2A
// 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;
/
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;
}
http://discussion.forum.nokia.com/fo...d.php?t=139032
使用的时候发现了小小问题,所以改进了一下,希望Cxt大大海涵~
用过MTM方式监控短信的兄弟应该知道,系统在收件箱创建新短信的时候一般是产生两次事件,EMsvEntriesCreated,EMsvEntriesChanged,而一般监控短信的例子都是严格按照这个顺序(在EMsvEntriesCreated中保存新建短信的TMsvId,在EMsvEntriesChanged时匹配)来监控的~
而上面的代码在创建新短信时则产生了三次事件,
EMsvEntriesCreated(iSmsMtm->Entry().CreateL(newIndexEntry);),
EMsvEntriesChanged(iSmsMtm->Entry().ChangeL(newIndexEntry);),
EMsvEntriesChanged(iSmsMtm->Entry().ChangeL(tttEntry);),
而iSmsMtm->SaveMessageL()会在收件箱生成CSmsPDU::ESmsSubmit类型的短信,这是我们所不需要的;为了跟系统创建新短信尽量一致,所以修改了一下代码:
TMsvId CSmsEngine::SaveMessageL(CSmsClientMtm& aSmsMtm, const TDesC& aAddress, const TDesC& aBody, const TTime& aTime) { aSmsMtm.SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId); TMsvEntry msvEntry; msvEntry.iDate = aTime; msvEntry.iMtm = KUidMsgTypeSMS; msvEntry.iType = KUidMsvMessageEntry; // in 3rd edition crashes here if capabilities are wrong msvEntry.iServiceId = aSmsMtm.ServiceId(); msvEntry.SetInPreparation(ETrue); msvEntry.SetUnread(ETrue); msvEntry.SetNew(ETrue); aSmsMtm.Entry().CreateL(msvEntry); TMsvId msvId = msvEntry.Id(); aSmsMtm.SwitchCurrentEntryL(msvId); CRichText& body = aSmsMtm.Body(); body.Reset(); body.InsertL(0, aBody); CSmsHeader* smsHeader = CSmsHeader::NewL(CSmsPDU::ESmsDeliver, body); CleanupStack::PushL(smsHeader); smsHeader->SetFromAddressL(aAddress); #ifdef EKA2 // 在3版aTime要用标准时间(TTime::UniversalTime()) TLocale locale; TTimeIntervalSeconds universalTimeOffset(locale.UniversalTimeOffset()); TInt numQuarterHours = universalTimeOffset.Int() / 900; #else // 在2版aTime要用当地时间(TTIme::HomeTime()); TInt numQuarterHours(0); #endif smsHeader->Deliver().SetServiceCenterTimeStamp(aTime, numQuarterHours); CMsvStore* msvStore = aSmsMtm.Entry().EditStoreL(); CleanupStack::PushL(msvStore); smsHeader->StoreL(*msvStore); // 保存信息头 msvStore->StoreBodyTextL(body); // 保存信息正文 msvStore->CommitL(); // 提交 CleanupStack::PopAndDestroy(2, smsHeader); msvEntry.SetReadOnly(ETrue); msvEntry.SetInPreparation(EFalse); msvEntry.iDetails.Set(aAddress); msvEntry.iDescription.Set(aBody); aSmsMtm.Entry().ChangeL(msvEntry); return msvId; }
感谢分享
关于时间,我直接这样用的
#ifndef __SERIES60_3X__
time.HomeTime();
#else
time.UniversalTime();
#endif
newIndexEntry.iDate.HomeTime();
=====>
newIndexEntry.iDate.UniversalTime();
Otherwise, it may cause inconsitency on E66 phone, which shows the time in the inbox list.
- 在收件箱创建短信
- 如何在收件箱创建短信
- 在android收件箱中创建一条短信
- 〔分享〕如何在收件箱创建短信
- 收件箱里创建一条新的未读短信的操作
- 短信收件箱的Intent跳转方法
- 单sim卡保存收件箱的短信到系统盘中
- 单sim卡保存收件箱的短信到系统盘中
- android手机开发之读取收件箱中指定号码短信
- android发送短信并监听插入收件箱的方法
- TreeView实现类似Outlook在收件箱后面显示新邮件数
- 在EXCEL中列出OUTLOOK收件箱里所有的邮件
- 安卓创建接收短信发送短信
- 如何在Outlook中查找并运行“收件箱修复工具”(Scanpst.exe)
- 如何在outlook里面把收件箱分组,以便快速的查看最重要的email。
- 这5个newsletter,设计师们可能想要放在收件箱
- Q:domino用户的新邮件不出现在$Inbox(收件箱),但可以在'所有文档'视图中看到
- Outlook Express 收件箱修复
- GDI绘制png
- 自定义的symbian图片控件,可在任意的位置放图片
- kangle web服务器---国内唯一提供技术服务的web服务器
- 放假了
- 469 - Wetlands of Florida
- 在收件箱创建短信
- MS SQL 所有字段
- 拖拽字体
- Linux USB鼠标驱动注解及测试
- 主机托管与虚拟主机等
- 调用symbian 浏览器打开指定网页
- 一个困扰我几天的struts2的问题!
- css学习总结
- 进程与程序的区别