androidxmppchatmessagingsmack

JXMPP & smack Android Library, Get Message Delivery Status


Em working on Chatting Application and everything is working perfectly, Now I want to check either my messages has been DELIVERED or SEEN by the receiver or not. For that purpose Em using DeliveryReceiptRequest of XMPP Library, I got the RequestID of the Message. But Em not sure how to get status by this ID. Can you please help me out? I want to finish it within next few hours.

Ask Questions whatever you want to Ask. I'll reply you instantly.

private void sendMessage(final String messageId, final String jid, final String content, final int chatType, final boolean isSticker) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Message message;
                Log.e("Send SMS" , "Step 4");

                try {
                    message = new Message(JidCreate.from(jid), content);
                    String deliveryReceiptId = DeliveryReceiptRequest.addTo(message);
                    Log.e("Numan Special", "sendMessage: deliveryReceiptId for this message is: " + deliveryReceiptId);
                    manageBoBExtension(message);
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                    Log.e("Send SMS" , "Step 7");
                    mListener.onError(e.getLocalizedMessage());
                    return;
                }

                message.setStanzaId(messageId);
                sendMessageDependingOnType(message, jid, chatType);
            }

            private void manageBoBExtension(Message message) {
                if (isSticker) {
                    Log.e("Send SMS" , "Step 5");
                    BoBHash bobHash = new BoBHash(Base64.encode(content), "base64");
                    message.addExtension(new BoBExtension(bobHash, null, null));
                }
                Log.e("Send SMS" , "Step 6");
            }
        }).start();
    }



private void sendMessageDependingOnType(Message message, String jid, int chatType) {
        if (chatType == Chat.TYPE_MUC_LIGHT) {
            MultiUserChatLightManager manager = XMPPSession.getInstance().getMUCLightManager();

            try {
                MultiUserChatLight multiUserChatLight = manager.getMultiUserChatLight(JidCreate.from(jid).asEntityBareJidIfPossible());
                multiUserChatLight.sendMessage(message);
            } catch (XmppStringprepException | InterruptedException | SmackException.NotConnectedException e) {
                mListener.onError(e.getLocalizedMessage());
            } finally {
                mListener.onMessageSent(message);
            }

        } else {
            ChatManager chatManager = RoomsListManager.getInstance().getChatManager();
            try {
                chatManager.createChat(JidCreate.from(jid).asEntityJidIfPossible()).sendMessage(message);
            } catch (InterruptedException | XmppStringprepException | SmackException.NotConnectedException e) {
                mListener.onError(e.getLocalizedMessage());
            } finally {
                mListener.onMessageSent(message);
            }
        }
    }

Solution

  • Before sending the message Add DeliveryReceiptRequest.addTo(yourMsg) after receiving Message on the other end send another xmpp Message using message.addExtension(new DeliveryReceipt(packet.getStanzaId)) then listen for updated status by implementing ReceiptReceivedListener. Also you can refer official Documentation here