Android smack server receipt ack
Asked Answered
O

2

3

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.

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

Omegaomelet answered 2/2, 2016 at 19:2 Comment(0)
I
18
  1. You need to save your messages by message id, you can get the id by message.getStanzaId().
  2. You have to enable stream management.

    static {
        XMPPTCPConnection.setUseStreamManagementDefault(true);
        XMPPTCPConnection.setUseStreamManagementResumptiodDefault(true);
    }
    
  3. 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();
    }
    

    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.

Ichnography answered 18/5, 2016 at 3:32 Comment(6)
what do you mean by this "Please take note that your server needs to enable stream management too.". In my case I am using ejabberd server?Tempestuous
Just make sure that stream_management is true in your Ejabberd configuration.Ichnography
@Haven: Thanks for your help, Is it also possible to send ack from the receiving client to server via stream management?Nicolettenicoli
@SarthakMittal SM sends ack from client to server itself, you don't need to do any extra implementation.Ichnography
Hi @Ichnography , smackLibVersion 4.3 doesn't have above method. Could you please share which method we need to use in version 4.3 for stanza acknowledgement. Thanks in advance.Mauri
Can someone help with this in smack 4.2?Uretic
H
2
connection.setUseStreamManagement(true);

It'll enable stream management (XEP-198) on the client side.

http://xmpp.org/extensions/xep-0198.html#acking

NB: It'll only work if the server supports XEP-198.

Highbrow answered 23/2, 2016 at 7:22 Comment(1)
Hi @Highbrow , could you please share any reference how to implement stanza acknowledgement in android. Thanks in advance.Mauri

© 2022 - 2024 — McMap. All rights reserved.