×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 36
  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    187

    Listen Incoming SMS through socket

    Hi,
    i want to Listen incoming SMS (from specific number) through Sockets, can any body provide me a sample code.

    Regards
    Asif Nazir

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: Listen Incoming SMS through socket

    There is no direct support for that. However this http://wiki.forum.nokia.com/index.php/SMS_Utilities_API exists.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    187

    Re: Listen Incoming SMS through socket

    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

  4. #4
    Regular Contributor
    Join Date
    May 2004
    Location
    Bangalore, India
    Posts
    118

    Re: Listen Incoming SMS through socket

    Here is the code which I am using for similar purpose...You can modify according to your requirement..

    ---The Header 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;
    };
    ---- The Source File -----

    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

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    187

    Re: Listen Incoming SMS through socket

    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

  6. #6
    Regular Contributor
    Join Date
    May 2004
    Location
    Bangalore, India
    Posts
    118

    Re: Listen Incoming SMS through socket

    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

  7. #7
    Regular Contributor
    Join Date
    Sep 2006
    Posts
    61

    Re: Listen Incoming SMS through socket

    One example is there in EMCC soft application for s60 MSgObserver u can refer that one which is suitable for you.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Posts
    187

    Re: Listen Incoming SMS through socket

    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

  9. #9
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Re: Listen Incoming SMS through socket

    Thanks Dushyant Gaur,
    Your example worked perfect for me.

  10. #10
    Regular Contributor
    Join Date
    Jul 2010
    Posts
    159

    Re: Listen Incoming SMS through socket

    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

  11. #11
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,335

    Re: Listen Incoming SMS through socket

    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

  12. #12
    Regular Contributor
    Join Date
    Jul 2010
    Posts
    159

    Re: Listen Incoming SMS through socket

    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....

  13. #13
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,335

    Re: Listen Incoming SMS through socket

    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

  14. #14
    Regular Contributor
    Join Date
    Jul 2010
    Posts
    159

    Re: Listen Incoming SMS through socket

    can i get ur email address, i may be needing a lot of help in future..

  15. #15
    Nokia Developer Champion
    Join Date
    Mar 2006
    Location
    Helsinki, Finland
    Posts
    8,335

    Re: Listen Incoming SMS through socket

    Quote Originally Posted by yahoo2010 View Post
    can i get ur email address, i may be needing a lot of help in future..
    This is why we have Forum Nokia Discussion boards. You can freely ask any of your query on appropriate section of Forum Nokia Discussion boards so that anyone can help you to solve your problems quick enough.
    Nokia Developer Wiki Moderation team

Page 1 of 3 123 LastLast

Similar Threads

  1. why it is not showing the incoming sms?....
    By bharats in forum Symbian C++
    Replies: 1
    Last Post: 2007-05-12, 06:36
  2. Flash SMS disappeared once incoming call arrives
    By Idith Eden in forum General Messaging
    Replies: 0
    Last Post: 2005-09-26, 06:03
  3. Replies: 0
    Last Post: 2005-09-20, 03:58
  4. Listen to SMS
    By boogieeee in forum General Messaging
    Replies: 1
    Last Post: 2004-06-03, 13:53

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •