×
Namespaces

Variants
Actions

Sending and receiving SMS (silent)

From Nokia Developer Wiki
Jump to: navigation, search

This code snippet describes how to send and receive SMS silently using Symbian C++.

Article Metadata
Code ExampleTested with
Devices(s): Nokia N97
Compatibility
Platform(s): S60 5th Edition
S60 5th Edition
Article
Created: mahbub_s60 (09 Dec 2011)
Last edited: hamishwillee (14 Jun 2013)

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

Related articles

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