AnsweredAssumed Answered

Detect failed messages

Question asked by Daniel Oliveira on Nov 24, 2016

I making a android chat app. Im use the api level 23, the Xmpp Smack lib version 4.1.8, and on server I use ejabberd, version 16.06.

I use this code to build a XMPP connection.


(TIMEOUT = 5000)


       private void buildConnection() {

       XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder()





               .setUsernameAndPassword(mUsername, mPassword)



       mConnection = new XMPPTCPConnection(;




       chatManager = ChatManager.getInstanceFor(mConnection);


       PingManager pingManager = PingManager.getInstanceFor(mConnection);





       ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(mConnection);





       if (mConnection != null) {

            DeliveryReceiptManager.getInstanceFor(mConnection).addReceiptReceivedListener(n ew ReceiptReceivedListener() {


               public void onReceiptReceived(String fromJid, String toJid, String receiptId, Stanza receipt) {


                    Log.i(TAG, "Confirmation stanza Got: " + receipt);







(the updateMessageStatusReceived(receipt) method is only to refresh the view).

after that, I connect and authenticate.


Everthing is normal, but when the connection is down, I need to resend the failed messages when the connection is restored. I didn't find any solution or event in Smack to detected if a message fails. Sometimes the delay of confirmation server stanza is high, and my app assumes that message fails but don't, and the other side receive many times the same message.


I build a Message object and send using this code:

    try {

            Chat chat = chatManager.createChat(chatMessage.getJid());


        } catch (SmackException.NotConnectedException e) {


        } catch (Exception e) {





When the connection is lost and I send message, no one exception is throw.

my question is: How I know the message realy fail, to try again?

Thanks, and sorry about the english.