1
當從設備發送短信時,下面的一段代碼應該打印出一條消息。我在模擬器上嘗試過幾次,但發送短信時沒有打印。我究竟做錯了什麼?爲什麼應用程序不接收短信已發送。OutboundMessageListener不檢測傳出短信
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!");
}
}