How to create the MMs & SMS
2010-03-29 13:59
387 查看
#ifndef __MMSCREATERMODEL_H__
#define __MMSCREATERMODEL_H__
#include <MSVAPI.H>
#include <mmsclient.h> // for CMmsClientMtm
class CMsvSession;
class CClientMtmRegistry;
//class CSmsClientMtm;
class CMMSCreateModel: public CBase, public MMsvSessionObserver
{
public:
static CMMSCreateModel* NewL();
//
static CMMSCreateModel* NewLC();
~CMMSCreateModel();
void CreateMMS();
void SendMMs();
protected:
void ConstructL();
private:
CMMSCreateModel();
//from MMsvSessionObserver
void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
private:
//
CMsvSession* iMsvSession;
//
CClientMtmRegistry* iClientMtMReg;
//
//CSmsClientMtm* iMMsClientMtm;
//
CMmsClientMtm* iSmsClientMtm;
//
CMsvEntry* iMsvEntry;
};
#endif
Here is the header file.
CMMSCreaterModel.cpp file
//
/*
* MMSCreateModel.cpp
*
* Created on: 29-Mar-2010
* Author: lujiado
*/
#include "MMSCreateModel.h"
#include <smut.h> ///KUidMsgTypeSMS
#include <mtclreg.h> // for CClientMtmRegistry
#include <msvids.h> // for Message type IDs
#include <MmsConst.h>
#include <CMsvMimeHeaders.h> // Attachemt mimeheader
#include <eikenv.h>
CMMSCreateModel* CMMSCreateModel::NewL()
{
CMMSCreateModel* self = CMMSCreateModel::NewLC();
CleanupStack::Pop(self);
return self;
}
CMMSCreateModel* CMMSCreateModel::NewLC()
{
CMMSCreateModel* self = new (ELeave)CMMSCreateModel();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CMMSCreateModel::ConstructL()
{
iMsvSession=CMsvSession::OpenAsyncL(*this);
//
iClientMtMReg = CClientMtmRegistry::NewL(*iMsvSession);
//
iSmsClientMtm = (CMmsClientMtm *)iClientMtMReg->NewMtmL( KUidMsgTypeMultimedia );
}
void CMMSCreateModel::CreateMMS()
{
//new entry of an object
CMsvEntry* entry = CMsvEntry::NewL(*iMsvSession,
KMsvGlobalOutBoxIndexEntryId, TMsvSelectionOrdering());
CleanupStack::PushL(entry);
//
iSmsClientMtm->SwitchCurrentEntryL(entry->EntryId());//get the current entry id
//create new message in folder
iSmsClientMtm->CreateMessageL(iSmsClientMtm->DefaultServiceL());
CleanupStack::PopAndDestroy();
//Settings receipients
iSmsClientMtm->AddAddresseeL(_L("13910593292"));
iSmsClientMtm->SetSubjectL(_L("Test MMS"));
//
TFileName attachmentFile;
attachmentFile.Append(_L("c://data//images//mmsexample.jpg"));
//
TMsvEntry ent = iSmsClientMtm->Entry().Entry();
ent.iType = KUidMsvMessageEntry;
ent.iServiceId = KMsvLocalServiceIndexEntryId;
ent.iMtm = KUidMsgTypeMultimedia;
ent.SetVisible(ETrue);//EFalse
ent.SetInPreparation(EFalse);
iSmsClientMtm->Entry().ChangeL(ent);
//Save this message
iSmsClientMtm->SaveMessageL();
//Opening store message
CMsvStore* store = iSmsClientMtm->Entry().EditStoreL();
CleanupStack::PushL(store);
//open attachment file
RFile attachment;
User::LeaveIfError(attachment.Open(CEikonEnv::Static()->FsSession(),
attachmentFile, EFileShareReadersOnly | EFileRead));
CleanupClosePushL(attachment);
//Mime header
CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
CleanupStack::PushL(mimeHeaders);
mimeHeaders->SetSuggestedFilenameL(_L("mmsexample.jpg"));
//
CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
CleanupStack::PushL(attaInfo);
//mime type
_LIT8(KMimeType,"image/jpeg");
//
TBufC8<12>mimeType(KMimeType);
TMsvAttachmentId attachId = KMsvNullIndexEntryId;
//attachment file must be an public foler
iSmsClientMtm->CreateAttachment2L(*store, attachment,
mimeType,*mimeHeaders,attaInfo,attachId);
CleanupStack::Pop(attaInfo);
CleanupStack::PopAndDestroy(mimeHeaders);
//
//
store->CommitL();
attachment.Close();
CleanupStack::PopAndDestroy();//attachment
CleanupStack::PopAndDestroy(store);
}
CMMSCreateModel::CMMSCreateModel()
{
}
CMMSCreateModel::~CMMSCreateModel()
{
if( iSmsClientMtm )
{
delete iSmsClientMtm;
iSmsClientMtm = NULL;
}
if( iClientMtMReg )
{
delete iClientMtMReg;
iClientMtMReg = NULL;
}
if( iMsvEntry )
{
delete iMsvEntry;
iMsvEntry = NULL;
}
if( iMsvSession )
{
delete iMsvSession;
iMsvSession = NULL;
}
}
void CMMSCreateModel::SendMMs()
{
//sending MMS
CMsvOperationWait* wait = CMsvOperationWait::NewLC();
wait->iStatus = KRequestPending;
CMsvOperation* Op = NULL;
Op = iSmsClientMtm->SendL(wait->iStatus);
wait->Start();
CleanupStack::PushL(Op);
CActiveScheduler::Start();
// the following is to ignore
while( wait->iStatus == KRequestPending )
CActiveScheduler::Start();
//
CleanupStack::PopAndDestroy(2);
}
void CMMSCreateModel::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3)
{
switch (aEvent)
{
case EMsvEntriesCreated :
{
break;
}
case EMsvServerReady:
{
break;
}
case EMsvMediaAvailable:
{
break;
}
default:
break;
}
}
Here I mainly study following Class:
CMsvSession class Represents a channel of communication between a client thread (Client-side MTM,
Interface MTM, or message client application) and
the Message Server thread.
in SDK »
Symbian OS v9.1
»
Symbian OS guide
»
Messaging
»
Using CDMA SMS Messaging
»
How to use the CDMA SMS MTM
#define __MMSCREATERMODEL_H__
#include <MSVAPI.H>
#include <mmsclient.h> // for CMmsClientMtm
class CMsvSession;
class CClientMtmRegistry;
//class CSmsClientMtm;
class CMMSCreateModel: public CBase, public MMsvSessionObserver
{
public:
static CMMSCreateModel* NewL();
//
static CMMSCreateModel* NewLC();
~CMMSCreateModel();
void CreateMMS();
void SendMMs();
protected:
void ConstructL();
private:
CMMSCreateModel();
//from MMsvSessionObserver
void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3);
private:
//
CMsvSession* iMsvSession;
//
CClientMtmRegistry* iClientMtMReg;
//
//CSmsClientMtm* iMMsClientMtm;
//
CMmsClientMtm* iSmsClientMtm;
//
CMsvEntry* iMsvEntry;
};
#endif
Here is the header file.
CMMSCreaterModel.cpp file
//
/*
* MMSCreateModel.cpp
*
* Created on: 29-Mar-2010
* Author: lujiado
*/
#include "MMSCreateModel.h"
#include <smut.h> ///KUidMsgTypeSMS
#include <mtclreg.h> // for CClientMtmRegistry
#include <msvids.h> // for Message type IDs
#include <MmsConst.h>
#include <CMsvMimeHeaders.h> // Attachemt mimeheader
#include <eikenv.h>
CMMSCreateModel* CMMSCreateModel::NewL()
{
CMMSCreateModel* self = CMMSCreateModel::NewLC();
CleanupStack::Pop(self);
return self;
}
CMMSCreateModel* CMMSCreateModel::NewLC()
{
CMMSCreateModel* self = new (ELeave)CMMSCreateModel();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
void CMMSCreateModel::ConstructL()
{
iMsvSession=CMsvSession::OpenAsyncL(*this);
//
iClientMtMReg = CClientMtmRegistry::NewL(*iMsvSession);
//
iSmsClientMtm = (CMmsClientMtm *)iClientMtMReg->NewMtmL( KUidMsgTypeMultimedia );
}
void CMMSCreateModel::CreateMMS()
{
//new entry of an object
CMsvEntry* entry = CMsvEntry::NewL(*iMsvSession,
KMsvGlobalOutBoxIndexEntryId, TMsvSelectionOrdering());
CleanupStack::PushL(entry);
//
iSmsClientMtm->SwitchCurrentEntryL(entry->EntryId());//get the current entry id
//create new message in folder
iSmsClientMtm->CreateMessageL(iSmsClientMtm->DefaultServiceL());
CleanupStack::PopAndDestroy();
//Settings receipients
iSmsClientMtm->AddAddresseeL(_L("13910593292"));
iSmsClientMtm->SetSubjectL(_L("Test MMS"));
//
TFileName attachmentFile;
attachmentFile.Append(_L("c://data//images//mmsexample.jpg"));
//
TMsvEntry ent = iSmsClientMtm->Entry().Entry();
ent.iType = KUidMsvMessageEntry;
ent.iServiceId = KMsvLocalServiceIndexEntryId;
ent.iMtm = KUidMsgTypeMultimedia;
ent.SetVisible(ETrue);//EFalse
ent.SetInPreparation(EFalse);
iSmsClientMtm->Entry().ChangeL(ent);
//Save this message
iSmsClientMtm->SaveMessageL();
//Opening store message
CMsvStore* store = iSmsClientMtm->Entry().EditStoreL();
CleanupStack::PushL(store);
//open attachment file
RFile attachment;
User::LeaveIfError(attachment.Open(CEikonEnv::Static()->FsSession(),
attachmentFile, EFileShareReadersOnly | EFileRead));
CleanupClosePushL(attachment);
//Mime header
CMsvMimeHeaders* mimeHeaders = CMsvMimeHeaders::NewL();
CleanupStack::PushL(mimeHeaders);
mimeHeaders->SetSuggestedFilenameL(_L("mmsexample.jpg"));
//
CMsvAttachment* attaInfo = CMsvAttachment::NewL(CMsvAttachment::EMsvFile);
CleanupStack::PushL(attaInfo);
//mime type
_LIT8(KMimeType,"image/jpeg");
//
TBufC8<12>mimeType(KMimeType);
TMsvAttachmentId attachId = KMsvNullIndexEntryId;
//attachment file must be an public foler
iSmsClientMtm->CreateAttachment2L(*store, attachment,
mimeType,*mimeHeaders,attaInfo,attachId);
CleanupStack::Pop(attaInfo);
CleanupStack::PopAndDestroy(mimeHeaders);
//
//
store->CommitL();
attachment.Close();
CleanupStack::PopAndDestroy();//attachment
CleanupStack::PopAndDestroy(store);
}
CMMSCreateModel::CMMSCreateModel()
{
}
CMMSCreateModel::~CMMSCreateModel()
{
if( iSmsClientMtm )
{
delete iSmsClientMtm;
iSmsClientMtm = NULL;
}
if( iClientMtMReg )
{
delete iClientMtMReg;
iClientMtMReg = NULL;
}
if( iMsvEntry )
{
delete iMsvEntry;
iMsvEntry = NULL;
}
if( iMsvSession )
{
delete iMsvSession;
iMsvSession = NULL;
}
}
void CMMSCreateModel::SendMMs()
{
//sending MMS
CMsvOperationWait* wait = CMsvOperationWait::NewLC();
wait->iStatus = KRequestPending;
CMsvOperation* Op = NULL;
Op = iSmsClientMtm->SendL(wait->iStatus);
wait->Start();
CleanupStack::PushL(Op);
CActiveScheduler::Start();
// the following is to ignore
while( wait->iStatus == KRequestPending )
CActiveScheduler::Start();
//
CleanupStack::PopAndDestroy(2);
}
void CMMSCreateModel::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3)
{
switch (aEvent)
{
case EMsvEntriesCreated :
{
break;
}
case EMsvServerReady:
{
break;
}
case EMsvMediaAvailable:
{
break;
}
default:
break;
}
}
Here I mainly study following Class:
CMsvSession class Represents a channel of communication between a client thread (Client-side MTM,
User
Interface MTM, or message client application) and
the Message Server thread.
in SDK »
Symbian OS v9.1
»
Symbian OS guide
»
Messaging
»
Using CDMA SMS Messaging
»
How to use the CDMA SMS MTM
相关文章推荐
- how to create colored 3D Objects using the OpenGL® ES cross-platform API.
- How to solve the "undefined reference to '__sync_sub_and_fetch_4'" compilation problem
- How to recreate the index fnd_lo…
- How to change the Windows Messenger(MSN)'s personal information using C++ - 用C++如何设置Windows Messenger(MSN)的个人信息
- How to properly use &#39;dd&#39; to benchmark the write speed of your disk?
- 打开Eclipse时出现"Failed to create the Java Virtual Machine"怎么办?
- 打开Eclipse时出现 "Failed to create the Java Virtual Machine
- How to create a custom directory for app files inside the ~/Library/Application Support directory.
- How to Create the CAPL DLL and integrated it into CANOE
- How To Fix Xcode's "used as the name of&
- HowTO: Create an Event Log Source in code, without the Permission errors
- How to Create Mixed Reality Videos for the Vive - with Two Controllers
- How to create Web Deployment Package and install the package
- How to create svn database on the ubuntu
- how to resolve the error message "Error reading Win32 manfest file"
- eclipse(优化四) eclipse启动时,报"failed to create the java virtual machine"的解决方案
- How to disable the warning message "File is probably not DOS format
- R12: How to add Microsoft Excel as Type to the Create Template List of Values in BI Publisher (Doc ID 1343225.1)
- Axure RP Pro - jQuery - How to implement the "set focus" action
- How to avoid the "enumeral mismatch" error in eikmenup.h