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
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
verificationcode=String.valueOf(myrandomnum.nextInt(9))+String.valueOf(myrandomnum.nextInt(9))+String.valueOf(myrandomnum.nextInt(9))+String.valueOf(myrandomnum.nextInt(9));

 

//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);
dc.send(dg);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
dc.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
} else {
MessageConnection mc = null;
try {
mc = (MessageConnection) Connector.open("sms://:0" + to);
TextMessage m = (TextMessage) mc.newMessage(MessageConnection.TEXT_MESSAGE);
m.setPayloadText("Test Message");
//m.setPayloadText(msg);
mc.send(m);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
try {
mc.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}
}
}

Highlighted
Developer
Posts: 17,011
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