How to create the MMs & SMS

#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值