How to create a SMS with attachment in inbox
文章信息
CMsvSession* messageSession;
CClientMtmRegistry* registry;
TFileName details;
TFileName description;
TFileName fileName;
TEntryInfoHolder infoHolder;
messageSession = CMsvSession::OpenSyncL(*this);
CleanupStack::PushL(messageSession);
registry = CClientMtmRegistry::NewL( *messageSession );
CleanupStack::PushL( registry );
infoHolder.messageSession = messageSession;
infoHolder.iEntryId = 0; // No entry yet !
CleanupStack::PushL( TCleanupItem( DeleteEntry, &infoHolder ) );
// Subject
_LIT(KSub, "InterGrafx");
details.Copy( KSub() );
// Description
description.Copy( igpFileName );
// Get message inbox
CMsvEntry* inbox=messageSession->GetEntryL( KMsvGlobalInBoxIndexEntryIdValue );
CleanupStack::PushL( inbox );
TMsvEntry newEntry;
// Child entry of inbox
// TMsvEntry
#ifdef __UIQV21__
newEntry.iMtm = TUid::Uid( KUidMsgTypeBT );
#endif
#ifdef __S60V12__
newEntry.iMtm = TUid::Uid( KUidMsgTypeBt );
#endif //
#ifdef __S60V22__
newEntry.iMtm = TUid::Uid( KUidMsgTypeBt.iUid );
#endif //__S60V22__
newEntry.SetVisible( EFalse );
newEntry.SetInPreparation( ETrue );
newEntry.iType = KUidMsvMessageEntry;
newEntry.iServiceId = KMsvUnknownServiceIndexEntryId;
newEntry.iDate.HomeTime();
newEntry.iSize = 120553;//todo
newEntry.iDetails.Set( details );
newEntry.iDescription.Set( description );
// For bio
// For future usage
//newEntry.iBioType = 0x101F3CD9;
//newEntry.iMtmData3 = 1;
//KMmsMessageMRetrieveConf | KMmsMessageMobileTerminated; // this defines MT message
//newEntry.iMtmData1 = 0;
//newEntry.iMtmData2 = 0;
//TUid aTypeUid;
//aTypeUid.iUid = 0x10000F6A;
//newEntry.iType = aTypeUid;
//TUid aMtmUid;
//aMtmUid.iUid = 0x10001262;
//newEntry.iMtm = aMtmUid;
inbox->CreateL(newEntry);
infoHolder.iEntryId=newEntry.Id();
CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL( *messageSession );
CleanupStack::PushL( mtmReg );
// Child entry of inbox
// CMsvEntry
CMsvEntry* entry = messageSession->GetEntryL( newEntry.Id() );
CleanupStack::PushL( entry );
CBaseMtm *mtm = mtmReg->NewMtmL( entry->Entry().iMtm );
// takes ownership
// The attachment will belong to it
mtm->SetCurrentEntryL( entry );
CleanupStack::Pop(); // entry
CleanupStack::PushL( mtm );
// Create an empty attachment
// On return, we get values of attachmentId, tempfileName
TFileName tempfileName;
TMsvId attachmentId;
mtm->CreateAttachmentL( attachmentId, tempfileName );
// Construct the path of the file to be created as attachment
HBufC* completeFilePath = HBufC::NewLC( 500 );
TPtr completeFilePathPtr = completeFilePath->Des();
completeFilePathPtr.Append( tempfileName );
completeFilePathPtr.Append( description );
Links
- Code snippets are taken from http://www.devdiv.com/
Best regards http://www.devdiv.com/


CMsvSession* messageSession; CClientMtmRegistry* registry; TFileName details; TFileName description; TFileName fileName; TEntryInfoHolder infoHolder;
messageSession = CMsvSession::OpenSyncL(*this); CleanupStack::PushL(messageSession);
registry = CClientMtmRegistry::NewL( *messageSession ); CleanupStack::PushL( registry );
infoHolder.messageSession = messageSession; infoHolder.iEntryId = 0; // No entry yet ! CleanupStack::PushL( TCleanupItem( DeleteEntry, &infoHolder ) );
// Subject _LIT(KSub, "InterGrafx"); details.Copy( KSub() );
// Description description.Copy( igpFileName );
// Get message inbox CMsvEntry* inbox=messageSession->GetEntryL( KMsvGlobalInBoxIndexEntryIdValue ); CleanupStack::PushL( inbox );
TMsvEntry newEntry;
// Child entry of inbox // TMsvEntry
Best regards http://www.devdiv.com/
newEntry.iMtm = TUid::Uid( KUidMsgTypeBT );
newEntry.iMtm = TUid::Uid( KUidMsgTypeBt );
newEntry.iMtm = TUid::Uid( KUidMsgTypeBt.iUid );
newEntry.SetVisible( EFalse ); newEntry.SetInPreparation( ETrue ); newEntry.iType = KUidMsvMessageEntry; newEntry.iServiceId = KMsvUnknownServiceIndexEntryId; newEntry.iDate.HomeTime(); newEntry.iSize = 120553;//todo newEntry.iDetails.Set( details ); newEntry.iDescription.Set( description );
// For bio // For future usage //newEntry.iBioType = 0x101F3CD9; //newEntry.iMtmData3 = 1; //KMmsMessageMRetrieveConf | KMmsMessageMobileTerminated; // this defines MT message //newEntry.iMtmData1 = 0; //newEntry.iMtmData2 = 0; //TUid aTypeUid; //aTypeUid.iUid = 0x10000F6A; //newEntry.iType = aTypeUid; //TUid aMtmUid; //aMtmUid.iUid = 0x10001262; //newEntry.iMtm = aMtmUid;
inbox->CreateL(newEntry); infoHolder.iEntryId=newEntry.Id();
CClientMtmRegistry* mtmReg = CClientMtmRegistry::NewL( *messageSession ); CleanupStack::PushL( mtmReg );
// Child entry of inbox // CMsvEntry CMsvEntry* entry = messageSession->GetEntryL( newEntry.Id() ); CleanupStack::PushL( entry );
CBaseMtm *mtm = mtmReg->NewMtmL( entry->Entry().iMtm ); // takes ownership // The attachment will belong to it mtm->SetCurrentEntryL( entry ); CleanupStack::Pop(); // entry CleanupStack::PushL( mtm );
// Create an empty attachment // On return, we get values of attachmentId, tempfileName TFileName tempfileName; TMsvId attachmentId; mtm->CreateAttachmentL( attachmentId, tempfileName );
// Construct the path of the file to be created as attachment HBufC* completeFilePath = HBufC::NewLC( 500 ); TPtr completeFilePathPtr = completeFilePath->Des(); completeFilePathPtr.Append( tempfileName ); completeFilePathPtr.Append( description );
Best regards http://www.devdiv.com/