×

Discussion Board

Results 1 to 6 of 6

Thread: Undetected SMS

  1. #1
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340

    Undetected SMS

    Hello Folks,

    I have a requirement that only my application should be able to detect certain messages, say for e.g. messages from a certain number or starting with a text pattern.

    I have already (successfully) tried the SMS via sockets example from Wiki (sadly it has a lot of errors). As long as my application runs, the messages are delivered to it, but as I close my application the native messaging application detects the incoming messages. I don't want this to happen. Can someone help me out? I am posting the code for reference.

    Function to send the SMS:

    Code:
    void CSMSEngine::SMSSendL()
    {
    	CSmsMessage* iSmsMessage;
    	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(iFs,CSmsPDU::ESmsSubmit,
    					buffer);
    			//Sets the message Service Center Address via which msg. 
    			//will be sent to receipent
    			iSmsMessage->SmsPDU().SetServiceCenterAddressL(_L("+919822078000"));
    			//Sets destination number
    			iSmsMessage->SmsPDU().SetToFromAddressL(_L("+919922920978"));
    			//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);
    		}
    	}
    }
    Function to read the received SMS / listen to the socket:
    Code:
    // -----------------------------------------------------------------------------
    // CSMSEngine::SocketListen()
    // Listens to incoming messages containing a match text.
    // -----------------------------------------------------------------------------
    //
    void CSMSEngine::SocketListen()
    {
    	LOGENTER;
    	_LIT(KTag, "#");
    	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)
    	{
    		LOGTXT("SOCKET OPENED!");
    		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)
    		{
    			LOGTXT("BINDING DONE!");
    			iPckgBuf() = KSockSelectRead;
    			//Applies an asynchronous I/O control operation on a socket.
    			iSocket.Ioctl( KIOctlSelect,iStatus, &iPckgBuf, KSOLSocket);
    			iRead=ETrue;
    			SetActive();
    		}
    		else
    			LOGTXT("BINDING FAILED!");
    	}
    	else
    		LOGTXT("SOCKET OPENING FAILED!");
    	LOGEXIT;
    }
    Function that does the actual reading of the message:
    Code:
    // -----------------------------------------------------------------------------
    // CSMSEngine::RunL()
    // Gets hit everytime a message with the 'tag' arrives
    // -----------------------------------------------------------------------------
    //
    void CSMSEngine::RunL()
    {
    	LOGENTER;
    	if(iRead)
    	{
    		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);
    		LOGDES16(iBuf);
    		iRead=EFalse;
    		SetActive();
    		CleanupStack::PopAndDestroy(smsBuffer);
    	}
    	LOGEXIT;
    }
    Last edited by ssn.kishore; 2008-10-01 at 11:17.
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

  2. #2
    Regular Contributor
    Join Date
    Nov 2007
    Location
    Pune, India
    Posts
    94

    Re: Undetected SMS

    Hi ssn.kishore,

    Do you mean that your application when running will act as a layer(filter) to the native messaging application and capture all(Number/Message pattern) messages that you want.

    So what is the problem in the code that you have posted?
    Can you elaborate on the problem in the code.
    Regards,
    Amey

  3. #3
    Regular Contributor
    Join Date
    Dec 2006
    Location
    Noida, India
    Posts
    115

    Re: Undetected SMS

    Hi Kishore,

    As long as my application runs, the messages are delivered to it, but as I close my application the native messaging application detects the incoming messages. I don't want this to happen.
    If you want to create a filter that filters the SMS with some text.. etc than you need to run a bacground process to capture an incoming SMS, read that SMS and if the string is found.. do whatever you like with the SMS.

    I don't want this to happen. Can someone help me out? I am posting the code for reference.
    But if you wont run a background exe or a application that tracks the SMS, then it is 110% sure thing that the SMS will be delivered to the native SMS application.

    It will be more helpful if you can clarify your problem.
    Thanks and Regards,
    Ravi

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,740

    Re: Undetected SMS

    That is normal, socket bindings are active as long as your socket is open. And it is obviously not open when your code is not running. So your code should run in the background, for example as an autostarted server.
    An other possibility is BIO messaging, where the SMS goes to the inbox, but your code is going to be executed when the user opens it.

  5. #5
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Pune, India
    Posts
    340

    Re: Undetected SMS

    Thanks for the replies folks!

    To clarify my requirement again, I don't wish the SMS to reach the Message server / Messaging application in any case, whether my application is running or not should't matter. As far as I understand from Wizard's answer, (sadly) such a thing is not possible Am I right Wizard?

    @Ravi, thanks for your interest and concern I hope I have clarified my problem for you.

    To respond to Amey, there is no problem in the code. I managed to remove some errors from the code example given on Wiki. I posted the code here for future / others' reference.
    Regards,
    Sainagakishore Srikantham (Kishore)

    Don't Hope, KNOW!!! ---------- Visit me at http://ssnkishore.blogspot.com ----------

  6. #6
    Regular Contributor
    Join Date
    Dec 2006
    Location
    Noida, India
    Posts
    115

    Re: Undetected SMS

    Hi Kishore,

    The only way to solve your problem is to run your exe(backgrouynD) or your application to handle the SMS before it reaches the Native SMS Application. BIO Message wont work for you. The code has no issues.
    Thanks and Regards,
    Ravi

Similar Threads

  1. problem sending CONCATENATED SMS
    By habier in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2007-07-11, 11:00
  2. Send SMS Problem. Cannot Get SMSC Address. Due to Strange SIM Card?
    By cksong in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-07-02, 16:13
  3. Replies: 1
    Last Post: 2005-12-01, 23:57
  4. Setting up SMS development environment
    By alecswan in forum Symbian Tools & SDKs
    Replies: 0
    Last Post: 2005-02-02, 18:28
  5. Replies: 2
    Last Post: 2002-10-02, 07:15

Posting Permissions

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