【问题标题】:Smack Message.setType() doesn't work, type is set to 'chat'Smack Message.setType() 不起作用,类型设置为“聊天”
【发布时间】:2015-01-29 09:11:31
【问题描述】:

我正在尝试使用 Type.headline

发送消息

这是我的代码:

  public boolean sendText(Chat chat, String text) {
        Message message = new Message();
        message.setBody(text);
        message.setType(Message.Type.headline);
        message.setPacketID("id123456");
        try {
           chat.sendMessage(message);
           Log.d("TAG", message.toXML().toString());
           return true;
        } catch (SmackException.NotConnectedException e) {}
        return false;
}

但是发送的 XML 是这样的:

<message id='id123456' to='roee@192.168.0.3' type='chat'>
   <body>test message</body>
   <thread>ed108b04-4488-423a-a441-ca95284db6c1</thread>
</message>

如您所见,在 XML 中 type='chat' 而不是 type='headline'。

为什么会这样,我该如何改变它?

【问题讨论】:

    标签: xmpp smack asmack


    【解决方案1】:

    因为您使用Chat 发送消息。

    只需使用 XMPPConnection.sendStanza(Stanza)(在旧 Smack 版本中使用 sendPacket(Stanza))即可向您发送带有标题类型的消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-05
      • 2015-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多