您的位置:首页 > 其它

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,
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐