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

New Contributor
Posts: 8
Registered: ‎02-12-2013
My Device: all
My Carrier: ..

sending sms blackberry application to mobile blackberry

hello ,

i am a beginner with developping blackberry application, i am trying to send verification code by sms, can someone please help me how can i send this message to the users of the application???


i tried this code:

public class SendSMS extends Thread {
private String to;
private String msg;
public SendSMS(String to, String msg) {


//verification code that we want to send


//getting the mobile number from the user
String Mobileno= MobilenoField.getText().toString();
selectedL = Mobileno;


this.to = selectedL;
this.msg = verificationcode;
public void run() {
if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {
DatagramConnection dc = null;
try {
dc = (DatagramConnection) Connector.open("sms://:0" + to);
byte[] data = "Test Message".getBytes();
// byte[] data = msg.getBytes();
Datagram dg = dc.newDatagram(dc.getMaximumLength());
dg.setData(data, 0, data.length);
} catch (IOException e) {
} finally {
try {
} catch (IOException e) {
} else {
MessageConnection mc = null;
try {
mc = (MessageConnection) Connector.open("sms://:0" + to);
TextMessage m = (TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE);
m.setPayloadText("Test Message");
} catch (IOException e1) {
} finally {
try {
} catch (IOException e) {

Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: sending sms blackberry application to mobile blackberry

to execute a thread call start()
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