Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 263
Registered: ‎10-27-2010
My Device: 8520
Accepted Solution

Code for receiving sms in blackberry

 

Hi i am developing a sample application to receive sms.....

 

It's working fine when it's in Startup and we are in application , but when i exit the application all incoming messages are received in native...

again if i start my application if we send sms then it's fine.

 

Below i am attaching my code snippet for listening thread

 

 



 public class ListeningThread extends Thread
    {
       private boolean _stop;
       private Connection _conn;
       private String _port = "3590";
        String decryptedText;
        private ListeningThread _listener;
        private synchronized void stop()
        {
            _stop = true;
            
            try
            {                
                if( _conn != null )
                {                    
                    _conn.close();
                }
            }
            catch (IOException ioe)
            {                
            }
        }   

       public void run()
        {
            try
            {               
                _conn =  Connector.open("sms://:0");
                for(;Smiley Wink
                {
                    if ( _stop )
                    {
                        return;
                    }
                    MessageConnection msgConn = (MessageConnection)_conn;
                    Message m = msgConn.receive();
                    receivedSmsMessage(m);                  
                }
            }
            catch (IOException ioe)
            {                             
                //updateStatus(ioe.toString());
            }
        }

   public boolean onSavePrompt()
        {
            return true;
        }    
    
        public void close()
        {           
            _listener.stop();
            
     //   _listener..run();                               
         //UiApplication.getUiApplication().requestBackground();
          //  super.close();
        }
 
   private void receivedSmsMessage(Message m)
    {
        String address = m.getAddress();
        String msg;
         String k=address.substring(9,19);
         byte[] bt=null;
             byte[] decryptedData;
        if ( m instanceof TextMessage )
        {
            TextMessage tm = (TextMessage) m;
            msg = tm.getPayloadText();
            bt=msg.getBytes();
        }
    
    }   
    
      public  static void errorDialog(final String message)
    {
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
            public void run()
            {
                Dialog.alert(message);
            }
        });
    }
      } 

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Code for receiving sms in blackberry

use an alternate entry point to have your background code run without interference of the ui application
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 263
Registered: ‎10-27-2010
My Device: 8520

Re: Code for receiving sms in blackberry

Hi Simon , Thanks for your reply...

 

If i use Alternate entry point then icon appears in the list, actually i don't want to show that icon also in the application list..

 

I already tried with alternate entry but not getting...please provide any snippet for me...

Developer
Posts: 17,011
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Code for receiving sms in blackberry

if you don't want an icon mark your application both as autostart and system module. instead of exiting the app just call requestBackground.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 263
Registered: ‎10-27-2010
My Device: 8520

Re: Code for receiving sms in blackberry

Hi Simon,

 

           By using Request background method my problem is solved....

 

Thanks a lot for your valuable suggestion....

New Contributor
Posts: 9
Registered: ‎12-27-2010
My Device: 9700
My Carrier: telenor

Re: Code for receiving sms in blackberry

guys i am student, i want to build a program that filters sms, if it is from blocked then it shouldnot go to inbox else it should go.

 

any code for this.

 

waiting for ur help

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Code for receiving sms in blackberry

Please refrain from posting in a solved thread.

 

There is no API that allows blocking an SMS from going into the inbox.

Contributor
Posts: 27
Registered: ‎02-20-2013
My Device: 9900
My Carrier: Telkomsel

Re: Code for receiving sms in blackberry

hi kiran, how to call your code from main class?

Regular Contributor
Posts: 92
Registered: ‎03-09-2013
My Device: bold 9800
My Carrier: blackberry

Re: Code for receiving sms in blackberry

Dear Sir,

 

i am developing application for sending and receiving SMS. I have development Sending Applocation. Can you kindly send me a sample application for receiving SMS.. I have searched alot but i didnt get any satisfactory result. I am new to Blackberry development. Please help me out..