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
ahmadahmad
Posts: 404
Registered: ‎05-31-2011
My Device: curve

send sms exception

hi, when i try use this code i get an IOException on conn.send(txtmessage) , can any one help me to now what's the problem !!
public void run(){ try{                      System.out.println("url::::::::::::::::::::::::::::::::::"+url);
 HttpConnection _httpConnection = (HttpConnection)Connector.open(url);
_httpConnection.setRequestMethod(HttpConnection.POST);
try{
  con = new Httpcons(_httpConnection, url);
   }
 catch(Exception fad)  {
                                                System.out.println(fad);
      }
MyApp.getUiApplication().invokeLater(new Runnable() {
                                        public void run() {
MessageConnection conn = (MessageConnection) Connector.open("sms://" + NUMBER);
                                   TextMessage txtmessage = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
                                   txtmessage.setPayloadText(TXT);
Thread th = new Thread() {
     public void run() {
       try{
         conn.send(txtmessage);
       }catch(Exception ex){}
}
}
})
}

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: send sms exception

using invokelater makes no sense in this context. and you don't start your thread.
otherwise the code looks good, please clean it up and try again.
----------------------------------------------------------
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
hemant_sain
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10

Re: send sms exception

apply simply like this.

 

public void sendSMS_GSM(String strMessage, String strNumber)
	{
		try {
				conn = (MessageConnection) Connector.open("sms://"+ strNumber);
				System.out.print("Message  " + strMessage+ "Number  "+strNumber);
				  //generate a new text message
				  TextMessage msgOut = (TextMessage)conn.newMessage(MessageConnection.TEXT_MESSAGE);
				  msgOut.setPayloadText(strMessage);
				  //finally send our message
				  conn.send(msgOut);
				  
			        
		} catch(Exception e) {
			System.out.println("Exception in SMS sending"+e.toString());
		} finally {
			try {
				conn.close();
				conn = null;
			} catch(Exception e){}
		}
	}

 

Developer
ahmadahmad
Posts: 404
Registered: ‎05-31-2011
My Device: curve

Re: send sms exception

I start the thread using start(); but the problem is on sending the sms I get an IOException on conn.send,

I try the sendSMS_GSM(...,...) function, like this :

public void run(){ 
		 HttpConnection _httpConnection = (HttpConnection)Connector.open(url);
		_httpConnection.setRequestMethod(HttpConnection.POST);
		try{
		  con = new Httpcons(_httpConnection, url);
		}
		 catch(Exception fad)  {
		    System.out.println(fad);
	      }
		 MyApp.getUiApplication().invokeLater(new Runnable() {
			 public void run() {
				 sendSMS_GSM("123", NUMBER);
	     }
	 }
		 )
	}

 but i get runtime exception ! 

Developer
hemant_sain
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10

Re: send sms exception

Once chek your network connection because this code is working fine for me.

Developer
ahmadahmad
Posts: 404
Registered: ‎05-31-2011
My Device: curve

Re: send sms exception

there is a connection, I think my problem is in a threading problem
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: send sms exception

i would suggest to remove the other code first, maybe Httpcons does not return etc.

and don't use invokelater, it does not make any sense there.
----------------------------------------------------------
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
hemant_sain
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10

Re: send sms exception

Once use that function out of the invokeLater().