You Are Here:

Community: Wiki

This page was last modified on 29 September 2009, at 12:26.

SMS Utilities API

From Forum Nokia Wiki

Reviewer Approved   
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

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:

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fSendingE5fSMSE5finE5fS60E5f3rdE5fE45ditionE5fE2dE5fMTMX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxSendingE20SMSE20inE20S60E203rdE20E45ditionE20E2dE20MTME20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZmessagingQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZsmsQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d04X qfnZuserE5ftagQSxcmsventryX qfnZuserE5ftagQSxdeletelX qfnZuserE5ftagQSxmessagingX qfnZuserE5ftagQSxs60X qfnZuserE5ftagQSxsmsX qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ