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
Highlighted
Developer
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Auto SMS problem?

Hello all,

 

I am trying to send Auto SMS when a button clicked from my application to my mobile number. I am following the below sample to do this.

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_is...

 

 

 

class FieldListener implements FieldChangeListener {
        public void fieldChanged(Field f, int context) {
            if ( f==myButtonClicked ) {
               
              try {
                
                MessageConnection msgConn = (MessageConnection)Connector.open("sms://mymobilenumber");
                Message msg = msgConn.newMessage(MessageConnection.TEXT_MESSAGE);
                TextMessage txtMsg = (TextMessage)msg;
                txtMsg.setPayloadText("Test Message From Me...");
                msgConn.send(txtMsg);
                
            } catch ( Exception e ) {
                    
                System.out.println( e.getMessage() );
                e.printStackTrace();
            }
        }
     }
    }

 

 

But when execute this code, this does not send any SMS to my mobile number, what is wrong here?

 

Can someone who has experince on this, please help me out?

 

Thank you.

 

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

Re: Auto SMS problem?

Is it a CDMA device?

 

See this thread (and many others if you seach for CDMA SMS):

 

http://supportforums.blackberry.com/t5/Java-Development/Unable-to-send-SMS-on-Verizon-device/m-p/215...

 

 

Developer
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Re: Auto SMS problem?

No. My device is GSM. I tried even the following code. It doesn't send SMS to mobile number.

 

 

 class FieldListener implements FieldChangeListener {
        public void fieldChanged(Field f, int context) {
            if ( f==buttonControl1 ) {
               
              try {
                           
                DatagramConnection dgConn;
                dgConn = ( DatagramConnection ) Connector.open( "sms://<MyMobileNumber>" );
                byte[] data = "Test Message".getBytes();
                Datagram dg = dgConn.newDatagram( dgConn.getMaximumLength() );
                dg.setData(data, 0, data.length);
                dgConn.send(dg);
  
            } catch ( Exception e ) {
                    
                System.out.println( e.getMessage() );
                e.printStackTrace();
            }
        }
     }
    }

 

 

Can someone please find what is the problem here?

 

 

Developer
Posts: 60
Registered: ‎08-20-2009
My Device: Not Specified

Re: Auto SMS problem?

Does not those SMS Api support for BB storm device?

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Auto SMS problem?

One question is why are you using == and not .equals() when you are comparing an object?