Smack Message.setType() 不起作用,类型设置为 'chat'
Smack Message.setType() doesn't work, type is set to 'chat'
我正在尝试使用 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'.
为什么会这样,我该如何更改它?
因为您使用 Chat
发送消息。
只需使用 XMPPConnection.sendStanza(Stanza)
(在较旧的 Smack 版本中使用 sendPacket(Stanza)
)即可向您发送带有标题类型的消息。
我正在尝试使用 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'.
为什么会这样,我该如何更改它?
因为您使用 Chat
发送消息。
只需使用 XMPPConnection.sendStanza(Stanza)
(在较旧的 Smack 版本中使用 sendPacket(Stanza)
)即可向您发送带有标题类型的消息。