2011-08-30 51 views
3

我试图使用XMPP的消息事件接口。据我了解,您可以标记您发送的邮件并附上“送达通知请求”标志,收件人不负责向您发送此通知。有没有人成功实施这个?有人可以给我一些示例代码吗?我的代码不起作用。我的听众(MessageEventNotificationListener,MessageEventRequestListener)回调从来不被称为:Android Smack MessageEventListener

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.chat); 

    PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 
    VajasKifli.connection.addPacketListener(this, filter); 

    tv = (TextView) findViewById(R.id.textView1); 
    tvState = (TextView) findViewById(R.id.textView2); 
    et = (EditText) findViewById(R.id.editText1); 
    et.addTextChangedListener(this); 

    mem = new MessageEventManager(VajasKifli.connection); 
    mem.addMessageEventNotificationListener(this); 
    mem.addMessageEventRequestListener(this); 

    sdm = new ServiceDiscoveryManager(VajasKifli.connection); 
    VajasKifli.log("sdm: " + sdm); 

    stateManager = ChatStateManager.getInstance(VajasKifli.connection); 

    recipient = getIntent().getStringExtra("recipient"); 
    chat = VajasKifli.connection.getChatManager().createChat(recipient, "chat-" + recipient, this); 
    VajasKifli.log("chat created: " + chat); 

    VajasKifli.connection.getChatManager().addChatListener(this); 

    sv = (ScrollView) findViewById(R.id.scrollView1); 

    handler = new ChatHandler(); 
} 

public void onClickSend(View view) 
{ 
    String text = et.getText().toString(); 
    if(text.length() > 0) 
    { 
     VajasKifli.log("sending text [" + text + "] to [" + recipient + "]"); 

     try 
     { 
      Message message = new Message(); 
      message.setBody(text); 
      MessageEventManager.addNotificationsRequests(message, false, true, false, false); 
      chat.sendMessage(message); 

      stateManager.setCurrentState(ChatState.active, chat); 
      lastState = ChatState.active; 
      tv.append("\n" + VajasKifli.connection.getUser().replaceFirst("@.*", "") + ": " + text); 
      sv.fullScroll(ScrollView.FOCUS_DOWN); 
     } 
     catch(XMPPException e) 
     { 
      VajasKifli.logError(e.toString()); 
     } 

     //showToast("sent: " + text); 
    } 
} 
+0

你可以请分享你如何解决这个问题? – Hunt

回答

2

你应该得到的XMPP连接的数据包的痕迹,无论是通过Wireshark的或通过咂嘴调试选项,以确保交付通知是真正由连接的另一端发送。如果不是这样,这就可以解释为什么没有调用监听器。

SMACK中的消息事件通过现在已过时的XEP-22完成。对方很有可能不执行这种过时的机制。

0

这太容易混淆了。现在我使用DefaultPacketExtension并发送自己需要的事件。这更简单,容易理解,并且很有效。

+0

可以请你分享你是如何解决这个问题的? –

+0

你可以让我知道如果你有任何解决方案@cuda – Roster

+0

你必须离开一个适当的解决方案... – chhameed