try this below code for sending text messages :
<small>public final class HelloBlackBerryScreen extends MainScreen
{
private BasicEditField basicEditField1, basicEditField2;
private String addr = "9888919119";
private String message = "This is a test message.";
public HelloBlackBerryScreen()
{
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
setTitle("Send SMS :");
basicEditField1 = new BasicEditField("To : ", addr, 11, BasicEditField.EDITABLE);
basicEditField2 = new BasicEditField("Message : ", message, 500, BasicEditField.EDITABLE);
ButtonField buttonField_1 = new ButtonField("Send", ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
buttonField_1.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field arg0, int arg1)
{
try
{
addr = basicEditField1.getText();
message = basicEditField2.getText();
sendSMS(addr, message);
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Error send msg : " + e.toString());
}
}
});
this.add(basicEditField1);
this.add(basicEditField2);
this.add(buttonField_1);
}
private void sendSMS(final String no, final String msg)
{
try
{
new Thread()
{
public void run()
{
if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA)
{
DatagramConnection dc = null;
try
{
dc = (DatagramConnection) Connector.open("sms://" + no);
byte[] data = msg.getBytes();
Datagram dg = dc.newDatagram(dc.getMaximumLength());
dg.setData(data, 0, data.length);
dc.send(dg);
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
try
{
System.out.println("Message Sent Successfully : Datagram");
Dialog.alert("Message Sent Successfully : Datagram");
}
catch (Exception e)
{
System.out.println("Exception **1 : " + e.toString());
e.printStackTrace();
}
}
});
}
catch (Exception e)
{
System.out.println("Exception 1 : " + e.toString());
e.printStackTrace();
}
finally
{
try
{
dc.close();
dc = null;
}
catch (IOException e)
{
System.out.println("Exception 2 : " + e.toString());
e.printStackTrace();
}
}
}
else
{
MessageConnection conn = null;
try
{
conn = (MessageConnection) Connector.open("sms://" + no);
TextMessage tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MESSAGE);
tmsg.setAddress("sms://" + no);
tmsg.setPayloadText(msg);
conn.send(tmsg);
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
try
{
System.out.println("Message Sent Successfully : TextMessage");
Dialog.alert("Message Sent Successfully : TextMessage");
}
catch (Exception e)
{
System.out.println("Exception **1 : " + e.toString());
e.printStackTrace();
}
}
});
}
catch (Exception e)
{
System.out.println("Exception 3 : " + e.toString());
e.printStackTrace();
}
finally
{
try
{
conn.close();
conn = null;
}
catch (IOException e)
{
System.out.println("Exception 4 : " + e.toString());
e.printStackTrace();
}
}
}
}
}.start();
}
catch (Exception e)
{
System.out.println("Exception 5 : " + e.toString());
e.printStackTrace();
}
}
protected boolean keyDown(int keycode, int status)
{
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE)
{
close();
return true;
}
return super.keyDown(keycode, status);
}
}</small>