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

Use SMS to notify an application

by Retired ‎02-16-2010 12:09 PM - edited ‎02-18-2010 10:50 AM (7,144 Views)


This article applies to the following:

  • BlackBerry® devices based on Java™
  • BlackBerry Java Development Environment (JDE)


Many applications have a back-end architecture that uses Short Message Service (SMS) to notify or communicate with the application. When porting this solution to BlackBerry devices, a common problem with legacy device models is that these SMS application messages may also appear in the BlackBerry device user’s inbox.

To set up the SMS listener, leverage the Connector.open() framework to open an SMS connection. When that connection is open, you can check for new messages. The following code sample is taken from the "Receive an SMS message" section in the BlackBerry Application Developer Guide Volume 1.

private static class ListeningThread extends Thread { 
private boolean _stop = false;
private DatagramConnection _dc;
public synchronized void stop() {
_stop = true;
try {
_dc.close(); // Close the connection so the thread returns.
} catch (IOException e) {
public void run() {
try {
_dc = (DatagramConnection)Connector.open("sms://");
for(;;) {
if ( _stop ) {
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
String address = new
String msg = new String(d.getData());
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
} catch (IOException e) {

To prevent this message from appearing in the BlackBerry device user’s inbox, the sending server should configure the SMS message so that the message type is a system message. This message type can be defined by setting the Protocol Identifier (TP-PID) to 64 (0x40), and the Digital Coding Scheme (TP-DCS) to 244 (0xF4), as shown below:


Note: TP-PID and TP-DCS show up in the above message as 40F4 in the octets in which they are expected. This definition will make sure that the SMS message will reach the receiving application but that the BlackBerry device user will not receive an alert, nor will they see it in their inbox.

Additional Information

For more information on SMS specifications, see the 3GPP™ web site.

Users Online
Currently online: 20 members 1,019 guests
Please welcome our newest community members: