Hi is there any way to do android xmpp client which will be able to get message receive confirmation (XEP-0184) I read that there is XEP-0184 in smack but normal smack is not working with android(or I can't do it) there is always SASL authentication exception.
How can I make use of XMPP XEP-0184 "Message Delivery Receipts" with Smack?
Smack received support for XEP-0184 with SMACK-331. You can't use Smack < 4.1 directly under Android, you need Smack 4.1 (or higher).
You can read more about Smack's XEP-0184 API in the javadoc of DeliveryReceiptManager.
When i use asmack i didn't see message confirmation i programs like xabber, should i enable xep-0184 in asmack? And if i should, tell me how I can' t find it out. –
Laudable
I have added a javadoc link –
Photochemistry
Now it work fine but I had to send receive confirmation manually like that: Packet received = new Message(); received.addExtension(new DeliveryReceipt(packet.getPacketID())); received.setTo(packet.getFrom()); connection.sendPacket(received); I really don't know why but DeliveryReceiptManager doesn't detect that there is in xml delivery receipt request. DeliveryReceiptManager.hasDeliveryReceiptRequest(packet) return false. –
Laudable
To enable automatic transmission of receipts, you need to call the following code right after the connection is logged in:
DeliveryReceiptManager .getInstanceFor(mXMPPConnection) .enableAutoReceipts();
- that will also ensure that a manager was created and bound to the connection. –
Futures Try
DeliveryReceiptManager.getInstanceFor(connection).autoAddDeliveryReceiptRequests();
–
Durant @Photochemistry when I try to send multiple messages, some messages do not receive delivery receipt, can you suggest a way to handle this? –
Adulate
Yes this works with normal Smack.
Gradle Dependencies
compile "org.igniterealtime.smack:smack-android:4.1.0"
compile "org.igniterealtime.smack:smack-tcp:4.1.0"
compile "org.igniterealtime.smack:smack-extensions:4.1.0" // <-- XEP-0184 classes
Prepare the XMPPTCPConnection i.e. before you connect() wire up a handler for when you get a delivery receipt
DeliveryReceiptManager.getInstanceFor(mConnection).addReceiptReceivedListener(new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(String fromJid, String toJid, String deliveryReceiptId, Stanza stanza) {
Log.d(TAG, "onReceiptReceived: from: " + fromJid + " to: " + toJid + " deliveryReceiptId: " + deliveryReceiptId + " stanza: " + stanza);
}
});
When sending a message, ensure you include a MessageReceiptRequest
Chat chat;
if (StringUtils.isNullOrEmpty(threadId)) {
chat = getChatManager().createChat(to);
Log.d(TAG, "sendMessage: no thread id so created Chat with id: " + chat.getThreadID());
} else {
chat = getChatManager().getThreadChat(threadId);
Log.d(TAG, "sendMessage: thread id was used to continue this chat");
}
Message message = new Message(to);
message.addBody("EN", messageText);
String deliveryReceiptId = DeliveryReceiptRequest.addTo(message);
chat.sendMessage(message);
Log.d(TAG, "sendMessage: deliveryReceiptId for this message is: " + deliveryReceiptId);
All done
Now, you can tell when a sent message has been received by the other side because the deliveryReceiptId obtained in the Chat.sendMessage(Message) code above will be logged by the onReceiptReceived callback set up earlier.
"When sending a message, ensure you include a MessageReceiptRequest" is not required, since you enabled automatic delivery receipt requests by calling
autoAddDeliveryReceiptRequests()
. –
Photochemistry fixed by removing the redundant call to: DeliveryReceiptManager.getInstanceFor(mConnection).autoAddDeliveryReceiptRequests(); –
Chronon
Why did you drop one LOC when you could have dropped multiple? –
Photochemistry
Because adding the delivery request explicitly to the outgoing message returns the delivery receipt id. If one uses the autoAddDeliveryReceiptRequests call it is unclear how to obtain this; i.e. an DeliveryReceiptRequest extension is not added to Messages automatically. –
Chronon
"i.e. an DeliveryReceiptRequest extension is not added to Messages automatically." No,
autoAddDeliveryReceiptRequest()
does exactly this: It adds automatically a delivery receipt request to every outgoing message stanza. Then you use DeliveryReceiptManager.addReceiptReceivedListener(ReceiptReceivedListener)
to get callbacks for the received receipts. –
Photochemistry A common use case is to communicate when a message has been confirmed to the user, via. the UI. Based on the code above we could persist the deliveryReceiptId along with the message content. The UI would display the message as not having been received yet. If a message is confirmed, onReceiptReceived can update the persisted message with the matching deliveryReceiptId as having been received. The UI layer can display the message as having been confirmed. –
Chronon
@Chronon do you get server acknowledgement using DeliveryReceiptManager ? –
Wasteland
one reason to do DeliveryReceiptRequest.addTo is if i don't want reciept of some message type e.g. normal message type.. And really thanks for your contribution @Photochemistry –
Dratted
© 2022 - 2024 — McMap. All rights reserved.