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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
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.