PDA

View Full Version : OutboundMessageListener doesn't detect outgoing sms


Lukaszz
07-17-2012, 09:52 AM
Hi, the following piece of code should print out a message when an sms is sent from the device. I've tried it several times on the simulator but nothing gets printed when I send an sms. What am I doing wrong? Why doesn't the app pick up that an sms has been sent?


public class BackGroundApp extends UiApplication implements OutboundMessageListener, javax.wireless.messaging.MessageListener {

private MessageConnection messageConnection;


public static void main(String args[])
{
BackGroundApp theApp = new BackGroundApp();
theApp.enterEventDispatcher();
}

public BackGroundApp(){
try {
MessageConnection _mc = (MessageConnection)Connector.open("sms://");
_mc.setMessageListener(this);

} catch (IOException e) {}

}

public void notifyIncomingMessage(MessageConnection messageconnection){


}

public void notifyOutgoingMessage(javax.wireless.messaging.Message message) {

System.out.println("SMS just sent from your device!");

}
}

hrbuckley
07-17-2012, 12:10 PM
1. You need to register your listener with the MessageConnection per the API documentation (http://www.blackberry.com/developers/docs/7.0.0api/net/rim/blackberry/api/sms/OutboundMessageListener.html).

2. The simulator can't really send SMS messages so you may have to do this on a device.