//试用方法:
CMtmEngine* iSmsHandler; //sms
//sms
iSmsHandler = CMtmEngine::NewL(*this);
//创建和发送短信
TBuf<256> bufCon(KNullDesC);
iMainView->GetNoticeValue(bufCon);
//创建短信
iSmsHandler->CreateDraftSMSL(aCallNumber, bufCon);
if (iSmsHandler->ValidateSMS())
{
iSmsHandler->SendSMSL();
}
/*
=======================================================================
=====
Name : MtmEngine.h
Author : nana
Version : 1.0
Copyright : Your copyright notice
Description : CMtmEngine declaration
=======================================================================
=====
*/
#ifndef MTMENGINE_H
#define MTMENGINE_H
//msgs.lib
//smcm.lib
//gsmu.lib
//euser.lib
#include <e32base.h> // For CActive, link against:
#include <e32std.h> // For RTimer, link against:
#include <msvapi.h> // MMsvSessionObserver
class MMsvSessionObserver;
class CMsvOperation;
class CMsvEntrySelection;
class CClientMtmRegistry;
class CSmsClientMtm;
class CMsvSession;
class TMsvSessionEvent;
class CMsvId;
// CONSTANTS
const TInt KSmsMessageLength = 512;
const TInt KAddressLength = 64;
class MMtmEngineObserver
{
public:
//发送短信
virtual void HandleMessageSentL(TInt aError)=0;
//接受短信
virtual void MessageReceived(TDesC& aMsg, TDesC& aAddr) = 0;
};
class CMtmEngine : public CActive, public MMsvSessionObserver
{
public:
// Cancel and destroy
~CMtmEngine();
// Two-phased constructor.
static CMtmEngine* NewL(MMtmEngineObserver & aObserver);
// Two-phased constructor.
static CMtmEngine* NewLC(MMtmEngineObserver & aObserver);
public:
// New functions
// Function for making the initial request
void StartL(TTimeIntervalMicroSeconds32 aDelay);
private:
// C++ constructor
CMtmEngine(MMtmEngineObserver & aObserver);
// Second-phase constructor
void ConstructL();
private:
// From CActive
// Handle completion
void RunL();
// How to cancel me
void DoCancel();
// Override to handle leaves from RunL(). Default
implementation causes
// the active scheduler to panic.
TInt RunError(TInt aError);
private:
enum TMtmEngineState
{
EUninitialized, // Uninitialized
EInitialized, // Initalized
EError
// Error condition
};
private:
TInt iState; // State of the active object
RTimer iTimer; // Provides async timing service
private:
MMtmEngineObserver & iObserver;
CMsvOperation * iOp;
CMsvEntrySelection * iEntrySelection;
CMsvSession * iSession;
CClientMtmRegistry * iMtmReg;
CSmsClientMtm * iSmsMtm;
TMsvId iSmsId;
CMsvEntry* iMsvEntry;
TMsvId iNewMessageId;
// Message body
TBuf<KSmsMessageLength> iMessage;
// Address (phonenumber)
TBuf<KAddressLength> iAddress;
private:
void CompleteConstructL();
void HandleSessionEventL(TMsvSessionEvent aEvent, TAny *aArg1,
TAny *aArg2,
TAny *aArg3);
public:
void CreateDraftSMSL(const TDesC & aAddress, const TDesC &
aContent);
TBool ValidateSMS();
void SendSMSL();
void SendSMS(const TDesC & aAddress, const TDesC & aContent);
};
#endif // MTMENGINE_H
symbian 短信的发送和监听
最新推荐文章于 2022-07-23 20:53:36 发布