【发布时间】:2017-06-14 07:16:36
【问题描述】:
我正在使用 Smack XMPP 创建一个聊天应用程序。除了读取/交付报告外,一切都运行良好。
这就是我发送交付报告的方式:
{
Message message = new Message();
message.setTo(chatMessage.getReceiver());
message.setType(Message.Type.normal);
message.setFrom(chatMessage.getSender());
message.setStanzaId(chatMessage.getReceiver() + "_" + CommonMethods.getCurrentGMTTime(0));
ChatMarker_File_XMPP_SERVER chatMarker_file_xmpp_server=new ChatMarker_File_XMPP_SERVER("received","urn:xmpp:chat-markers:0" , true);
chatMarker_file_xmpp_server.setIdValue(chatMessage.getMsgid());
message.addExtension(chatMarker_file_xmpp_server);
Mychat = ChatManager.getInstanceFor(connection).createChat(
message.getTo() + "@"
+ context.getString(R.string.server),
mMessageListener);
try {
if (connection.isAuthenticated()) {
/********************************************************
* ******** MESSAGE SEND **********************
***/
Mychat.sendMessage(message);
} else {
login();
}
} catch (SmackException.NotConnectedException e) {
Log.e("xmpp.SendMessage()", "msg Not sent!-Not Connected!");
} catch (Exception e) {
Log.e("SendMessage()-Exception",
"msg Not sent!" + e.getMessage());
}
}
但问题是Mychat.sendMessage(message); SendMessage 方法正在这样做
/**
* Sends a message to the other chat participant. The thread ID, recipient,
* and message type of the message will automatically set to those of this chat.
*
* @param message the message to send.
* @throws NotConnectedException
*/
public void sendMessage(Message message) throws NotConnectedException {
// Force the recipient, message type, and thread ID since the user elected
// to send the message through this chat object.
message.setTo(participant);
message.setType(Message.Type.chat);
message.setThread(threadID);
chatManager.sendMessage(this, message);
}
现在虽然我明确将“messageType”设置为“正常”,但“sendMessage()”再次将其转换为Type.Chat。
我已经检查了其他可能的方法和文档,以便我可以通过 Type normal 发送一条消息,但找不到任何东西。
谢谢
【问题讨论】: