Em正在处理聊天应用程序,并且一切运行正常,现在我想检查消息是否已被接收方传送或发送。为此,使用XMPP库的DeliveryReceiptRequest,我得到了消息的RequestID。但是Em不确定如何通过此ID获取状态。你能帮我吗?我想在接下来的几个小时内完成。
随便问问题。我会立即回复您。
private void sendMessage(final String messageId, final String jid, final String content, final int chatType, final boolean isSticker) {
new Thread(new Runnable() {
@Override
public void run() {
Message message;
Log.e("Send SMS" , "Step 4");
try {
message = new Message(JidCreate.from(jid), content);
String deliveryReceiptId = DeliveryReceiptRequest.addTo(message);
Log.e("Numan Special", "sendMessage: deliveryReceiptId for this message is: " + deliveryReceiptId);
manageBoBExtension(message);
} catch (XmppStringprepException e) {
e.printStackTrace();
Log.e("Send SMS" , "Step 7");
mListener.onError(e.getLocalizedMessage());
return;
}
message.setStanzaId(messageId);
sendMessageDependingOnType(message, jid, chatType);
}
private void manageBoBExtension(Message message) {
if (isSticker) {
Log.e("Send SMS" , "Step 5");
BoBHash bobHash = new BoBHash(Base64.encode(content), "base64");
message.addExtension(new BoBExtension(bobHash, null, null));
}
Log.e("Send SMS" , "Step 6");
}
}).start();
}
private void sendMessageDependingOnType(Message message, String jid, int chatType) {
if (chatType == Chat.TYPE_MUC_LIGHT) {
MultiUserChatLightManager manager = XMPPSession.getInstance().getMUCLightManager();
try {
MultiUserChatLight multiUserChatLight = manager.getMultiUserChatLight(JidCreate.from(jid).asEntityBareJidIfPossible());
multiUserChatLight.sendMessage(message);
} catch (XmppStringprepException | InterruptedException | SmackException.NotConnectedException e) {
mListener.onError(e.getLocalizedMessage());
} finally {
mListener.onMessageSent(message);
}
} else {
ChatManager chatManager = RoomsListManager.getInstance().getChatManager();
try {
chatManager.createChat(JidCreate.from(jid).asEntityJidIfPossible()).sendMessage(message);
} catch (InterruptedException | XmppStringprepException | SmackException.NotConnectedException e) {
mListener.onError(e.getLocalizedMessage());
} finally {
mListener.onMessageSent(message);
}
}
}
答案 0 :(得分:1)
在发送消息之前,在另一端接收到消息后添加DeliveryReceiptRequest.addTo(yourMsg)
,使用message.addExtension(new DeliveryReceipt(packet.getStanzaId))
发送另一个xmpp消息,然后通过实现ReceiptReceivedListener
来监听更新的状态。您也可以参考官方文档here