2013-04-07 60 views
1

我正在使用smack发送聊天消息。在测试中我发现,当网络不可访问时,API不会抛出任何异常。如何使用Smack发送聊天时检测到错误

我的代码:

Chat chat = connection.getChatManager().createChat(
     "[email protected]", new MessageListener() { 

      @Override 
      public void processMessage(Chat arg0, Message arg1) { 
       System.out.println(arg1.getFrom() + " says " + arg1.getBody()); 

      } 
     }); 
// I Put a break point here and deliberately disable the network. 
// But the following line is not throwing the XMPPException 

chat.sendMessage("smack says hi.."); /* Send the message  */ 

我应该添加任何侦听器来捕获异常?

+0

试试这个:http://xmpp-tutorials.blogspot.com.br/ – Richard 2014-06-30 23:27:40

回答

0

由于是异步调用,您不会得到异常。如果您想知道连接是否已被删除,则必须使用连接注册ConnectionListener。

相关问题