在 smack 中获取最近消息的传递状态 [英] get delivery status of recent messages in smack

查看:26
本文介绍了在 smack 中获取最近消息的传递状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 smack 4.2.4 和 xmpp 的新手.我已经发送了一堆消息,但 Recipent 无法获取它们,我已经关闭了应用程序,下次打开应用程序时想要检查消息的状态,无论是否发送.

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.

推荐答案

您可以使用 XEP-0184: Message Delivery Receipts 用于检查消息到目的地的传递.首先你必须添加 smack-extensions 的 gradle 依赖:

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
    }
});

考虑在您发送消息时,随机的唯一节 ID (sid)将设置为您的节.您必须将其保存在数据库中的消息行中,然后您可以在收到回执时使用此sid进行识别.

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.

这篇关于在 smack 中获取最近消息的传递状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆