我正在使用Smack XMPP创建聊天应用。除了Read / Deliver报告之外,一切都很好。
这就是我发送投放报告的方式:
{
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'设置为'normal'但是'sendMessage()'再次将其转换为Type.Chat
。
我已经检查了其他可能的方法和文档,以便以某种方式我可以使用类型正常发送消息,但找不到任何东西。
由于
答案 0 :(得分:2)
为什么不使用Delivery Receipt Manager?
发送消息时:
Message message = new Message();
String deliveryReceiptId = DeliveryReceiptRequest.addTo(message);
message.setType(Message.Type.chat);
你可以收到如下传递知识..
DeliveryReceiptManager.getInstanceFor(connection).addReceiptReceivedListener(new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
//here receiptId will be same as deliveryReceiptId u sent above which means msg is delivered to recipient
}
});
}
如果您希望将消息发送到服务器状态,请在此处查看我的答案: https://stackoverflow.com/a/44254615/6350239
并且为了实现msg读取状态,您需要实现自定义阅读回执,例如https://stackoverflow.com/a/29001653/6350239