Join Now
Quality Rating:
  • Currently 5.0 / 5
(5.0 / 5 - 1 vote cast)
This page was last modified 18:54, 24 June 2008.

SMS Utilities API

From Forum Nokia Wiki

Note!
This API is not part of the public SDK. It can be found in the SDK API Plug-in.


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

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

SilentSMS Application

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 Discussions
Thread Thread Starter Forum Replies Last Post
Doubt with Nokia 6020... walabarse General Messaging 0 2006-03-31 12:38
Location api jsr 179 and Bluetooth GPS prategiov Mobile Java General 21 2007-12-04 23:36
如何根据用户选择的安装版本(简体、繁体)在安装时显示相应简、繁体的release_note? goready@163.com Symbian 2 2005-10-07 10:38
3410 sms api killy13 Mobile Java General 1 2003-07-04 12:27
关于位图显示 heng222-z Symbian 3 2007-02-06 07:43
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZmessagingQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtopicQUqfnTopicZsmsQ
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX
     
    
            
            RDF Facets:
            
            
                        qfnZuserE5FtagQSxgloabalnoteX
                        qfnZuserE5FtagQSxmakesisX
                        qfnZuserE5FtagQSxtapatasX