I'm newby in smack 4.2.4 and xmpp. I've sent bunch of messages but the recipent is not available to get them,I've close the application and next time when I'll open the application want to check the status of messages, which is delivered or not.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use XEP-0184: Message Delivery Receipts for check delivery of messages to destination. First you must add the gradle dependency of smack-extensions:
implementation 'org.igniterealtime.smack:smack-extensions:4.2.2;
Then use this code, when you want to send a message, to add receipt request to stanza:
DeliveryReceiptRequest.addTo(message);
Then you can receive the delivery status in a listener like this:
DeliveryReceiptManager d = DeliveryReceiptManager.getInstanceFor(connection);
d.addReceiptReceivedListener(new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
Log.i("delivery", "for: " + receiptId + " received");
//here you can use sid or receiptId to identify which message is delivered
}
});
Consider that when you are sending message, a random unique stanza-id (sid) will be setted to your stanza. you must save it in your message row in database, then you can identify that with this sid when receipt received.