Android smack服务器回执ack [英] Android smack server receipt ack

查看:88
本文介绍了Android smack服务器回执ack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用XMPP制作聊天应用程序.为此,我提到了

I'm trying to make a chat application using XMPP. For this, I referred to this tutorial and successfully implemented it. But now I'm unable to get that particular message is received by the server and update my local DB. Please give me any idea how to do this.

我正在使用chatId保存一条消息.那么我可以通过哪种方式获得收据消息ID?

I'm saving a message with chatId. So from which method of smack do I get this receipt message id?

推荐答案

  1. 您需要按消息ID保存消息,可以通过message.getStanzaId()获取ID.
  2. 您必须启用流管理.

static {
    XMPPTCPConnection.setUseStreamManagementDefault(true);
    XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true);
}

  • 发送消息时,您将为该消息添加一个ack侦听器,就像这样.

  • when you send out a mesage, you add an ack listener for that message, like this.

    try {
        if (mConnection.isSmEnabled()) {
            try {
                mConnection.addStanzaIdAcknowledgedListener(message.getStanzaId(), new StanzaListener() {
                    @Override
                    public void processPacket(Stanza packet) throws NotConnectedException {
                        updateMessageStatus(packet);
                    }
                });
            } catch (StreamManagementException.StreamManagementNotEnabledException e) {
                e.printStackTrace();
            }
        }
        mConnection.sendStanza(message);
    } catch (NotConnectedException e) {
        e.printStackTrace();
    }
    

    现在,在updateMessageStatus(packet)方法中,您可以通过id(packet.getStanzaId())在数据库中找到消息,并将状态从待处理"更新为已发送".

    Now, inside updateMessageStatus(packet) method, you find message in your database by id (packet.getStanzaId()) and update status from "pending" to "sent".

    请注意,您的服务器也需要启用流管理.

    Please take note that your server needs to enable stream management too.

  • 这篇关于Android smack服务器回执ack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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