×
Namespaces

Variants
Actions
(Difference between revisions)

SMS Utilities API

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Tidy content)
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix reviewer approved and ArticleMetaData)
Line 1: Line 1:
 +
{{ArticleMetaData <!-- v1.1 -->
 +
|sourcecode= [[Media:SilentSMS.zip]]
 +
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 +
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
 +
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
 +
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
 +
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase -->
 +
|id= <!-- Article Id (Knowledge base articles only) -->
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20070616
 +
|author= [[User:Ltomuta]]
 +
}}
 
[[Category:Messaging]][[Category:Symbian C++]]
 
[[Category:Messaging]][[Category:Symbian C++]]
{{ReviewerApproved|timestamp=20090929}}
+
 
 
{{Abstract|SMS Utilities API provides methods for sending the sms using sockets.}}
 
{{Abstract|SMS Utilities API provides methods for sending the sms using sockets.}}
  
Line 144: Line 167:
 
* [[Reading SMS from Inbox]]
 
* [[Reading SMS from Inbox]]
 
* [[Sending SMS in S60 3rd Edition - MTM]]
 
* [[Sending SMS in S60 3rd Edition - MTM]]
* [[SMS Operations]]
+
* [[SMS operations using Symbian C++|SMS Operations]]
 
* [[How to send an SMS using sockets]]
 
* [[How to send an SMS using sockets]]
 
* [[Sending-Receiving SMS through an Exe (Server)]]
 
* [[Sending-Receiving SMS through an Exe (Server)]]

Revision as of 08:21, 2 February 2012

Article Metadata
Code Example
Source file: Media:SilentSMS.zip
Article
Created: ltomuta (16 Jun 2007)
Last edited: hamishwillee (02 Feb 2012)

SMS Utilities API provides methods for sending the sms using sockets.

Note.pngNote: 

  • This API is not part of the public SDK. It can be found in the SDK API Plug-in.
  • NB! If another application has already opened the socket then this method fails!

Use cases

Sending and receiving SMS silently (that is without the message tone and without any new message notification) can be achieved by sending SMS through sockets and also by listening for incoming SMS with the help of sockets.

Example code

SMSSendL() method is responsible for sending the sms using sockets.

void SMSSendL()
{
//iFileServer is RFs object
iFileSession.Connect();
//iSockerServer is RSocketServ object
iSocketServer.Connect();
//iSocket is RSocket Object
TInt err1 = iSocket.Open(iSocketServer,KSMSAddrFamily,
KSockDatagram, KSMSDatagramProtocol);
if(!err1)
{
//SMS address for a socket.
TSmsAddr smsaddr;
//Only for sending, no reception.
smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly);
TInt BindErr1= iSocket.Bind(smsaddr);
if(BindErr1 == KErrNone)
{
CSmsBuffer *buffer = CSmsBuffer::NewL();
CleanupStack::PushL(buffer);
//Inserting msg. to be sent to a buffer
buffer->InsertL(0, _L("MyMessage"));
//Stream that writes a CSmsMessage object across a socket
RSmsSocketWriteStream writestream(iSocket);
//ESmsSubmit-SMS-SUBMIT, sent from Mobile Station to Service Center
iSmsMessage = CSmsMessage::NewL(iFileSession,CSmsPDU::ESmsSubmit,
buffer);
//Sets the message Service Center Address via which msg.
//will be sent to receipent
iSmsMessage->SmsPDU().SetServiceCenterAddressL(_L("+01234567890"));
//Sets destination number
iSmsMessage->SmsPDU().SetToFromAddressL(_L("+09876543210"));
//Externalises message to a stream which is used for
//writing data into the socket
iSmsMessage->ExternalizeL(writestream);
//Ensures that any buffered data is written to the stream.
writestream.CommitL();
TPckgBuf<TInt> sendBuffer;
sendBuffer=KSockSelectWrite;
//Applies an asynchronous I/O control operation on a socket.
iSocket.Ioctl(KIoctlSendSmsMessage,iStatus,&sendBuffer,KSolSmsProv);
iRead=EFalse;
SetActive();
CleanupStack::PopAndDestroy(buffer);
}
}
}

SMSRead() is responsible for Reading incoming SMS silently.Actually it checks whether the incoming message is of a specific patern(In this case the message should start with "##")

void SMSRead()
{
TBuf8<2> matchTag;
_LIT8(KTag1,"##");
matchTag.Copy(KTag);
iReadServer.Connect();
//Opens a socket by creating a new subsession to the socket server.
TInt err = iReadSocket.Open(iReadServer,KSMSAddrFamily,
KSockDatagram, KSMSDatagramProtocol);
if(!err)
{
TSmsAddr smsAddr;
// App. listens for sms msgs with some special tag in it.
smsAddr.SetSmsAddrFamily(ESmsAddrMatchText);
smsAddr.SetTextMatch(KTag1);
TInt bindErr = iReadSocket.Bind(smsAddr);
if(!bindErr)
{
sbuf() = KSockSelectRead;
//Applies an asynchronous I/O control operation on a socket.
iReadSocket.Ioctl( KIOctlSelect,iStatus, &sbuf, KSOLSocket);
iRead=ETrue;
SetActive();
}
}
}
void RunL()
{
if(iRead)
{
iFileSession.Connect()
TBuf<2> matchTag;
matchTag.Copy(KTag);
CSmsBuffer *buffer=CSmsBuffer::NewL();
CleanupStack::PushL(buffer);
//Stream that reads a CSmsMessage object across a socket.
RSmsSocketReadStream readStream(socket1);
//Allocates and creates a CSmsMessage
//ESmsDeliver-SMS-DELIVER, sent from service center to Station.
CSmsMessage message = CSmsMessage::NewL
TheFs1,CSmsPDU::ESmsDeliver,buffer);
CleanupStack::PushL(message);
 
//Internalises data from stream to CSmsMessage
message->InternalizeL(readStream);
readStream.Close();
//Extracting the received message to a buffer
TBuf<255> msgContents;
message->Buffer().Extract(msgContents,0,message->Buffer().Length());
CleanupStack::PopAndDestroy(2)
//compare whether the incoming message starts with "##"
if( (buf1.Left(2)).Compare(matchTag) == 0)
{
iReadSocket.Ioctl( KIoctlReadMessageSucceeded,iStatus, &sbuf,KSolSmsProv);
//Now msgContents contains the actual message.
iRead=EFalse;
SetActive();
}
}
}

Note: sBuf is of type TPckgBuf<TUint>

Example Application

File:SilentSMS.zip


See Also

See RSendAs class for sending SMS and CMsvSession and MMsvSessionObserver::HandleSessionEventL() for receiving SMS with public APIs. This approach may play the incoming message tone.

Related Links:

145 page views in the last 30 days.