You Are Here:

Community: Wiki

This page was last modified on 14 November 2008, at 07:15.

Series 60第三版上提取消息的附件

From Forum Nokia Wiki

S60 3rd上的MTM框架提供了MMsvAttachmentManager(附件管理器)这个接口类管理各种不同消息的附件,它把操作各种附件的实现交给各MTM,使用者只需要简单通过附件管理器提供的方法就可以操作消息的附件。附件管理器基于CMsvAttachment管理各类型的附件,而CMsvAttachment是消息框架中提供的用来表现任何类型附件的对象,通过它不用实际加载或检索附件就可得到附件的许多属性。消息管理器支持下面几种不同类型的附件:

1. 文件附件:被拷贝或创建在消息存储(Message Store)中的文件。

2. 文件链接附件:附件是链接到磁盘中的文件,没有拷贝到消息存储(Message Store)中。

3. 消息条目(Entry):系统中的消息可以注册为别一个消息的附件。

下面的代码演示了如何通过MMsvAttachmentManager提取消息中的附件:

//Extract attachments to specified path
void CMsgEngine::ExtractAttachmentL( const TDesC &aNewPath, CDesCArray &aFileNameArray, TMsvId aEntryId )
{
aFileNameArray.Reset();
CMsvEntry* msvEntry = iSession->GetEntryL( aEntryId );
CleanupStack::PushL( msvEntry );
if( !msvEntry->HasStoreL() )
{
CleanupStack::PopAndDestroy( msvEntry );
return;
}
CMsvStore *store = msvEntry->ReadStoreL();
CleanupStack::PushL( store );
MMsvAttachmentManager& attachManager = store->AttachmentManagerL();
RFs fileSession;
User::LeaveIfError( fileSession.Connect() );
CleanupClosePushL( fileSession );
for( TInt i = 0; i < attachManager.AttachmentCount(); ++i )
{
CMsvAttachment *attachment = attachManager.GetAttachmentInfoL( i );
CleanupStack::PushL( attachment );
TPtrC8 mime = attachment->MimeType();
CMsvAttachment::TMsvAttachmentType type = attachment->Type();
if( type != CMsvAttachment::EMsvMessageEntry )
{
TFileName newPath( aNewPath );
newPath.Append( attachment->AttachmentName() );
aFileNameArray.AppendL( attachment->AttachmentName() );
RFile file = attachManager.GetAttachmentFileL( i );
TInt size(0);
file.Size( size );
HBufC8 *buf = HBufC8::NewLC( size );
TPtr8 ptrBuf( buf->Des() );
file.Read( ptrBuf, size );
RFile newFile;
User::LeaveIfError ( newFile.Replace( fileSession, newPath, EFileWrite ) );
newFile.Write( ptrBuf );
newFile.Close();
CleanupStack::PopAndDestroy( buf );
}
CleanupStack::PopAndDestroy( attachment );
}
CleanupStack::PopAndDestroy( 3, msvEntry );
}

有人可能会注意到CMsvAttachment已经提供了AttachmentName()和FilePath()方法来提供附件的名称与路径,那为什么不使用BaflUtils:: CopyFile()等API直接复制?测试一下就可以发现这些附件是存储在私有目录下的,其它程序没有AllFiles是不能访问的,所以需要使用MMsvAttachmentManagerr::GetAttachmentFileL()返回的RFile来读取文件数据,另外注意返回的RFile是以只读的形式打开文件,所以不能对附件进行修改。

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fCE2eBE2eSE5fME45SSAGE45X qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxCE2eBE2eSE20ME45SSAGE45E20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZjavaQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZmessagingQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxjavaX qfnZuserE5ftagQSxmessagingX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ