Hi,
i want to Listen incoming SMS (from specific number) through Sockets, can any body provide me a sample code.
Regards
Asif Nazir
Hi,
i want to Listen incoming SMS (from specific number) through Sockets, can any body provide me a sample code.
Regards
Asif Nazir
There is no direct support for that. However this http://wiki.forum.nokia.com/index.php/SMS_Utilities_API exists.
Thanks wizard_hu_:
i have used the code from the linlk that u have provided me. it is successfully listening first SMS but after that it is not listen any more sms, can any body tell me me,
i have used the code mentioned below.
void SocketListen()
{
_LIT(KTag, "1");
TBuf8<2> matchTag;
matchTag.Copy(KTag);
//Opens a socket by creating a new subsession to the socket server.
TInt err = iSocket.Open(iSocketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol);
if(err==KErrNone)
{
TRequestStatus iStatus;
TSmsAddr smsaddr;
// App. listens for sms msgs with some special tag in it.
smsaddr.SetSmsAddrFamily(ESmsAddrMatchText);
smsaddr.SetTextMatch(matchTag);
TInt BindErr = iSocket.Bind(smsaddr);
if(BindErr == KErrNone)
{
iPckgBuf() = KSockSelectRead;
//Applies an asynchronous I/O control operation on a socket.
iSocket.Ioctl( KIOctlSelect,iStatus, &iPckgBuf, KSOLSocket);
SetActive();
iRead=ETrue;
}
}
}
void RunL()
{
if(iRead)
{
TRequestStatus iStatus;
CSmsBuffer *smsBuffer = CSmsBuffer::NewL();
CleanupStack::PushL(smsBuffer);
//Stream that reads a CSmsMessage object across a socket.
RSmsSocketReadStream readStream(iSocket);
//Allocates and creates a CSmsMessage
//ESmsDeliver-SMS-DELIVER, sent from service center to Mobile Station.
iSmsMessage = CSmsMessage::NewL(iFs,CSmsPDU::ESmsDeliver,smsBuffer);
//Internalises data from stream to CSmsMessage
iSmsMessage->InternalizeL(readStream);
readStream.Close();
//Extracting the received message to a buffer
iSmsMessage->Buffer().Extract(iBuf,0,iSmsMessage->Buffer().Length());
iSocket.Ioctl( KIoctlReadMessageSucceeded,iStatus, &iPckgBuf, KSolSmsProv);
//Printing the received Message.
CAknInformationNote* note122=new(ELeave) CAknInformationNote;
note122->ExecuteLD(iBuf);
iBuf.Zero();
iRead=EFalse;
CleanupStack::PopAndDestroy(smsBuffer);
SetActive();
}
}
Thanks in advance, plz reply as early as possible
Regards
Asif Nazir
Here is the code which I am using for similar purpose...You can modify according to your requirement..
---The Header File -----
---- The Source File -----Code:#include <e32base.h> #include <es_sock.h> #include <f32file.h> #include <smsuaddr.h> #include <smsustrm.h> #include <Gsmumsg.h> #include <in_sock.h> #define MAX_APP_PATH_LEN 150 #define MAX_LOG_PATH_LEN 20 #ifdef __UI_FRAMEWORKS_V2__ #define LOG_FILES "\\SmsReceiverLogs.txt" #else #define LOG_FILES "\\system\\apps\\SmsReceiverLogs.txt" #endif _LIT8(KGdpSmsHeaderTag, "//"); enum SmsStatus { ReadSmsStatus, ReceiveSmsStatus }; enum KN_BOOL { KN_FALSE = 0, KN_TRUE }; class SmsReceiver : public CActive { public: static SmsReceiver* NewL(); static SmsReceiver* NewLC(); ~SmsReceiver(); void Open(); void ReceiveSms(); private: void ConstructL(); SmsReceiver(); void ReadSms(); void ReadSmsBuffer(); void RunL(); void DoCancel(); private: RSocket mRSocket; RSocketServ mRSocketServer; RFs mRFs; TPckgBuf<TUint> mOctlResult; CSmsMessage *iSmsMsg; SmsStatus mSmsStatus; };
Code:#include <gsmubuf.h> #include <utf.h> #include <stdio.h> #include <apgtask.h> #include <utf.h> #include <e32std.h> #include <e32base.h> #include <stdlib.h> #include <e32des8.h> #include <string.h> #include <stdio.h> #include "Smsreceiver.h" SmsReceiver::SmsReceiver() :CActive(CActive::EPriorityLow) { mSmsStatus = ReadSmsStatus; } SmsReceiver* SmsReceiver::NewL() { SmsSender *sender = SmsSender::getInstance(); SmsReceiver* self = SmsReceiver::NewLC(); CleanupStack::Pop(self); return self; } SmsReceiver* SmsReceiver::NewLC() { SmsReceiver* self = new (ELeave) SmsReceiver(); CleanupStack::PushL(self); self->ConstructL(); return self; } void SmsReceiver::ConstructL() { CActiveScheduler::Add(this); User::LeaveIfError(mRSocketServer.Connect()); User::LeaveIfError(mRFs.Connect()); } void SmsReceiver::Open() { // Open a socket User::LeaveIfError(mRSocket.Open(mRSocketServer, KSMSAddrFamily, KSockDatagram, KSMSDatagramProtocol)); // Set the pattern to search for in incoming SMS messages. Messages which do not have our // signature will be consumed by the Messaging Application. TSmsAddr smsAddr; smsAddr.SetSmsAddrFamily(ESmsAddrMatchText); smsAddr.SetTextMatch(KGdpSmsHeaderTag()); User::LeaveIfError(mRSocket.Bind(smsAddr)); } void SmsReceiver::ReceiveSms() { // Wait for incoming messages mOctlResult()= KSockSelectRead; mRSocket.Ioctl(KIOctlSelect, iStatus, &(mOctlResult), KSOLSocket); SetActive(); mSmsStatus = ReadSmsStatus; } void SmsReceiver::RunL() { switch(mSmsStatus) { case ReceiveSmsStatus: { ReadSmsBuffer(); Open(); ReceiveSms(); } break; case ReadSmsStatus: { ReadSms(); } break; } } void SmsReceiver::ReadSms() { // Create an empty message and buffer for our incoming message. CSmsBuffer* buffer=NULL; buffer=CSmsBuffer::NewL(); iSmsMsg = CSmsMessage::NewL(mRFs, CSmsPDU::ESmsSubmit, buffer); // Read the message. RSmsSocketReadStream readstream(mRSocket); readstream >> *(iSmsMsg); // Let the socket know that we have read the message and it can be removed from the message // store. mRSocket.Ioctl(KIoctlReadMessageSucceeded, iStatus, NULL, KSolSmsProv); SetActive(); mSmsStatus = ReceiveSmsStatus; } void SmsReceiver::ReadSmsBuffer() { TInt length= iSmsMsg->Buffer().Length(); HBufC* buffer16 = HBufC::NewLC(length); TPtr body16(buffer16->Des()); body16.FillZ(length); iSmsMsg->Buffer().Extract(body16,0,length); HBufC8* buffer8 = HBufC8::NewLC(length+1); TPtr8 body8(buffer8->Des()); body8.FillZ(length+1); body8.Copy(body16); // Convert from address from uncode and send to handler TPtrC ptrFrom = iSmsMsg->ToFromAddress(); HBufC8* hFromAddress = HBufC8::NewLC(ptrFrom.Length()+10); //as advised by pratap. TPtr8 address = hFromAddress->Des(); address.FillZ(ptrFrom.Length()); address.Copy(ptrFrom); ////////////USE THE SMS TEXT //////// CleanupStack::PopAndDestroy(); // buffer16 CleanupStack::PopAndDestroy(); // buffer8 CleanupStack::PopAndDestroy(); // hFromAddress; if(iSmsMsg) { delete iSmsMsg; iSmsMsg = NULL; } /////////////////////////// mRSocket.Close(); ///////////////////////////// } void SmsReceiver::DoCancel() { mRSocket.CancelIoctl(); } SmsReceiver::~SmsReceiver() { Cancel(); mRSocket.Close(); mRSocketServer.Close(); mRFs.Close(); }
Dushyant Gaur
Sling Media,
Bangalore
cell:+91 9342276086
email: dushyantg@slingmedia.com
Thanks dgaur:
It solved my problem but i also want to listen Outgoing SMS and also read all receipient numbers along Data, how can i do that.
Thanks in advance
Regards
Asif Nazir
I guess for your case, you can monitor the message store for any folder (inbox/outbox/sent) state change and retreive the message details. There is some Messaging example code on forum...YOu can search and try....
Dushyant Gaur
Sling Media,
Bangalore
cell:+91 9342276086
email: dushyantg@slingmedia.com
One example is there in EMCC soft application for s60 MSgObserver u can refer that one which is suitable for you.
Thanks for reply
i have successfully track incoming sms through sockets having specific text in it but when i restart my set all messages that i have tracked will arrived 1 b 1 in the inbox how can i delete them from message store at the time of tracking.
Regards
Asif Nazir
Thanks Dushyant Gaur,
Your example worked perfect for me.
t will be so kind of u if u can spare some time in helping me in my code.
i want to develop a application for N97 which could read incomming sms before it reaches inbox and i can perfom a spam check on it thn move it to inbox folder. i have searched over internt and i found out that it is possible through socckets.... there is code available about sockets on nokia forum... but its not working.... i m not even sure about that code even it will work on Qt creator or not. cuz i m using qt creator for development.
it will be very nice of u, if u provide any help
If you are developing for Symbian C++ then you should use Carbide.c++ IDE. Yes, It is possible to read the messages before they move into Inbox. Check this Wiki article: http://wiki.forum.nokia.com/index.php/SMS_Operations
By the way, which Wiki article you were referring which you say does not work? How does it not work?
Nokia Developer Wiki Moderation team
hey kiran thanx for reply...
http://wiki.forum.nokia.com/index.php/SMS_Utilities_API
i downloaded the file named silentsms.zip on this link but i dnt knw i dont know how to run it on QT creator cuz ther isnt any .pro file which is supposed to be a project file to work on qt creator....
As said, you should develop for Symbian C++ with Carbide.c++ IDE. You can download it free from here: http://www.forum.nokia.com/Library/T...r/Carbide.c++/
Nokia Developer Wiki Moderation team
can i get ur email address, i may be needing a lot of help in future..