2012-07-17 51 views
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!"); 

    } 
} 

回答

2
  1. 您需要按照API documentation的MessageConnection註冊您的聽衆。

  2. 模擬器無法真正發送短信,因此您可能必須在設備上執行此操作。