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

Use SMS to notify an application

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

Summary


This article applies to the following:

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


Procedure


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) {
System.err.println(e.toString());
}
}
public void run() {
try {
_dc = (DatagramConnection)Connector.open("sms://");
for(;;) {
if ( _stop ) {
return;
}
Datagram d = _dc.newDatagram(_dc.getMaximumLength());
_dc.receive(d);
String address = new
String(d.getAddress());
String msg = new String(d.getData());
System.out.println("Message received: " + msg);
System.out.println("From: " + address);
System.exit(0);
}
} catch (IOException e) {
System.err.println(e.toString());
}
}
}




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:



07913180998000F0040491369740F43080224100238A1168656C6C6F62696E61727974706964363


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.



Contributors
Users Online
Currently online: 4 members 1,861 guests
Recent signins:
Please welcome our newest community members: