×
Namespaces

Variants
Actions

Sending SMS with RSendAs

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Platform Security
Capabilities: NetworkServices
Article
Keywords: RSendAs
Created: symbianyucca (20 Mar 2007)
Last edited: hamishwillee (14 Jun 2013)

CRSendAsSender illustrates how to send SMS message using RSendAs in Symbian OS 9.x. To use it just construct the SMS sender by using the static NewL function. The first parameter is reference to the callback observer, which is used to notify when the message is sent.

aMessage argument is used to supply the message body and the aRecipients is used to supply the recipients phone number.

Note that the current implementation of the RSendAs is using default settings values (which can not really be changed) and the message body is converted to the 7-bit-sms format, and all characters that are not defined in the 7-bit-sms format will be replaced with question marks.

Contents

Library needed:

LIBRARY    sendas2.lib

RSendAs_SMS.cpp

CRSendAsSender* CRSendAsSender::NewL(MRSendSMSObserver& aObserver,const TDesC& aMessage,const TDesC& aRecipients)
{
CRSendAsSender* self = new (ELeave) CRSendAsSender(aObserver);
CleanupStack::PushL(self);
self->ConstructL(aMessage, aRecipients);
CleanupStack::Pop(self);
return self;
}
 
CRSendAsSender::CRSendAsSender(MRSendSMSObserver& aObserver):CActive(0),iObserver(aObserver)
{
}
 
CRSendAsSender::~CRSendAsSender()
{
Cancel();
iSendAsMessage.Close();
iSendAs.Close();
}
 
void CRSendAsSender::ConstructL(const TDesC& aMessage,const TDesC& aRecipients)
{
CActiveScheduler::Add(this);
 
User::LeaveIfError(iSendAs.Connect());
iSendAsMessage.CreateL(iSendAs, KUidMsgTypeSMS);
 
iSendAsMessage.AddRecipientL(aRecipients, RSendAsMessage::ESendAsRecipientTo);
iSendAsMessage.SetBodyTextL(aMessage);
 
iSendAsMessage.SendMessage(iStatus);
SetActive();
}
 
void CRSendAsSender::DoCancel()
{
iSendAsMessage.Cancel();
}
 
void CRSendAsSender::RunL()
{
iObserver.MessageSentL(iStatus.Int());
}

RSendAs_SMS.h

#include <e32base.h>
#include <F32FILE.H>
#include <BADESCA.H>
 
#include <rsendasmessage.h>
#include <rsendas.h>
#include <MTCLREG.H>
 
class MRSendSMSObserver
{
public:
virtual void MessageSentL(TInt aError) = 0;
};
 
class CRSendAsSender : public CActive
{
public:
static CRSendAsSender* NewL(MRSendSMSObserver& aObserver,const TDesC& aMessage,const TDesC& aRecipients);
~CRSendAsSender();
protected:
void DoCancel();
void RunL();
private:
CRSendAsSender(MRSendSMSObserver& aObserver);
void ConstructL(const TDesC& aMessage,const TDesC& aRecipients);
private:
MRSendSMSObserver& iObserver;
RSendAs iSendAs;
RSendAsMessage iSendAsMessage;
};

Related Links:

This page was last modified on 14 June 2013, at 09:34.
63 page views in the last 30 days.