I have just switch to Smack 4.1 from depreciated asmack. Smack 4.1 is automatically sending receipts with wrong id attached which is causing exception in my case.
我刚从折旧的asmack切换到Smack 4.1。 Smack 4.1会自动发送附有错误ID的收据,这会导致我的情况发生异常。
Smack 4.1 is attaching 2 different id's with receipt
Smack 4.1附加了2个不同的ID和收据
Here is the chat message received
这是收到的聊天消息
RECV (0): <message from='***' to='***' xml:lang='en' id='65' kind='0' type='chat'><body>vhh</body><request xmlns='urn:xmpp:receipts'/></message>
Here is the received receipt generated by Smack 4.1 in response of chat message
这是Smack 4.1响应聊天消息而生成的收据
SENT (0): <message to='***' id='roZ7C-32' type='chat'><received xmlns='urn:xmpp:receipts' id='65'/></message>
Smack 4.1 is attaching 2 different ids with Received Receipt id='roZ7C-32' and id='65'
Smack 4.1附加了2个不同的ID,其中收到的收据ID ='roZ7C-32'和id ='65'
My Question ares :
我的问题是:
- How can I make these 2 ids same
- How can I disable the receipts so that I can generate my custom recipts
我怎样才能使这两个ID相同
如何禁用收据以便我可以生成自定义收件人
2 个解决方案
#1
For your first question , to get the ID of the sent message the code would be:
对于您的第一个问题,要获取已发送消息的ID,代码将为:
Message ms = new Message();
ms.addBody("EN", Messegeforsend);
DeliveryReceiptRequest.addTo(ms); //tells that you will need delivery for this message
String send_message_id= ms.getStanzaId();
and you can get the ID for delivered message which would be same as the ID for the sent message :
并且您可以获取已发送消息的ID,该ID与发送消息的ID相同:
deliveryReceiptManager = DeliveryReceiptManager.getInstanceFor(connection);
deliveryReceiptManager.addReceiptReceivedListener(new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(String arg0, String arg1, String arg2,Stanza arg3) {
String delivered_message_id = arg2;
}
});
the send_message_id would be exactly equal to delivered_message_id, so you would know which message has been delivered
send_message_id将完全等于deliver_message_id,因此您可以知道哪条消息已经发送
#2
SMACK 4.1.0 message receive listener to write below code
SMACK 4.1.0消息接收监听器写下面的代码
try {
Message ms = new Message();
ms.addBody("EN", "deleriyed");
ms.setTo(message.getFrom());
ms.setStanzaId(message.getStanzaId());
DeliveryReceiptRequest.addTo(ms);
connection.sendStanza(ms);
} catch (NotConnectedException e) {
e.printStackTrace();
}
#1
For your first question , to get the ID of the sent message the code would be:
对于您的第一个问题,要获取已发送消息的ID,代码将为:
Message ms = new Message();
ms.addBody("EN", Messegeforsend);
DeliveryReceiptRequest.addTo(ms); //tells that you will need delivery for this message
String send_message_id= ms.getStanzaId();
and you can get the ID for delivered message which would be same as the ID for the sent message :
并且您可以获取已发送消息的ID,该ID与发送消息的ID相同:
deliveryReceiptManager = DeliveryReceiptManager.getInstanceFor(connection);
deliveryReceiptManager.addReceiptReceivedListener(new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(String arg0, String arg1, String arg2,Stanza arg3) {
String delivered_message_id = arg2;
}
});
the send_message_id would be exactly equal to delivered_message_id, so you would know which message has been delivered
send_message_id将完全等于deliver_message_id,因此您可以知道哪条消息已经发送
#2
SMACK 4.1.0 message receive listener to write below code
SMACK 4.1.0消息接收监听器写下面的代码
try {
Message ms = new Message();
ms.addBody("EN", "deleriyed");
ms.setTo(message.getFrom());
ms.setStanzaId(message.getStanzaId());
DeliveryReceiptRequest.addTo(ms);
connection.sendStanza(ms);
} catch (NotConnectedException e) {
e.printStackTrace();
}