Different ways to send SMS messages

by Retired ‎02-16-2010 01:33 PM - edited ‎02-17-2010 04:08 PM (7,755 Views)


This article applies to the following:

  • BlackBerry® Device Software 4.0 and later


The following approaches can be used in applications to send Short Message Service (SMS) messages on the BlackBerry smartphone:

1. Use a DatagramConnection from the javax.microedition.io package:

DatagramConnection dgConn; 
dgConn = (DatagramConnection)Connector.open("sms://15195555555");
byte[] data = "Test Message".getBytes();
Datagram dg = dgConn.newDatagram(dgConn.getMaximumLength());
dg.setData(data, 0, data.length);

2. Use a MessageConnection from the javax.wireless.messaging package:

MessageConnection msgConn = (MessageConnection)Connector.open("sms:// 15195555555");
Message msg = msgConn.newMessage(MessageConnection.TEXT_MESSAGE);
TextMessage txtMsg = (TextMessage)msg;
txtMsg.setPayloadText("Test Message");