Sending and receiving SMS (silent)
This code snippet describes how to send and receive SMS silently.
Article Metadata
Code Example
Compatibility
Article
Contents |
Introduction
This code snippet describes how to send short message (SMS) and handling silent SMS. It shows in a single class how we can handle both SMS sending and receiving. When this demo application runs on any Symbian device, it monitors the SMS socket and intercept the message if it has "secret" word in it. If it has no "secret" word then it works without any effect.
In the following code snippet KSMSPrefixString has been specified as _LIT8(KSMSPrefixString, "secret"). If you want to monitor for other word you could change it.
User::LeaveIfError(iSocketServer.Connect());
// Open SMS socket
User::LeaveIfError(iSmsSocket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol));
// Set SMS prefix - only intercept SMS messages starting with a particular string
TSmsAddr smsAddress;
smsAddress.SetSmsAddrFamily(ESmsAddrMatchText);
smsAddress.SetTextMatch(KSMSPrefixString);
iSmsSocket.Bind(smsAddress);
Handling both Sender and Receiver
CENgineSMSSendReceive class handles both sending and receiving. This class is derived from MSecretSMSReceiverObserver and MSecretSMSSenderObserver class. When we send a SMS then the result is inform with a call back mechanism by MSecretSMSSenderObserver class. In turns, engine class inform the UI class with MEngineObserverObserver. When message is delivered or new secret message comes then the call back function inform the UI by creating a note.
class CENgineSMSSendReceive : public CBase, public MSecretSMSReceiverObserver, public MSecretSMSSenderObserver
{
public:
void SendMessage();
private:
// from MSecretSMSReceiverObserver
void NewSecretSmsReveicedL( const TDesC& aSMSMsg );
// from MSecretSMSSenderObserver
void SmsSendResult( TInt aError );
private:
CENgineSMSSendReceive(MEngineObserverObserver & aEngineObserverObserver);
private:
CSecretSmsSender *iSecretSmsSender;
CSecretSMSReceiver *iSecretSMSReceiver;
MEngineObserverObserver & iEngineObserverObserver;
RFs iFsSession;
};
Compiling and testing
The code was tested with N97, it was a quick demo for discussion purpose. If you wish to send sms then change the number in the following line of ENgineSMSSendReceive.cpp file. numbers->AppendL(_L("+35840ADDNumber")); // TODO
Download the example for Symbian phones: Media:SilentSMSSendReceive.zip


(no comments yet)