I am using smack and openfire for create chat app in android . for message status I have no problem with delivered and displayed message in other client (double check). I will send a simple json message like bellow to sender: {"delivery":timestapmp} and parse it and double check messages with lower than timestamp that sent before. the problem is about sent status (one check). When i send message the server no response anything that message has sent . is it possible in smack to send message with callback from server. if possible and is it possible to send time server in callback response . thanks .
Asked
Active
Viewed 2,654 times
3
-
which is the version of smack you are using – Raut Darpan May 27 '17 at 05:19
-
last version , 4.2 – Hosein Kord May 27 '17 at 05:21
-
see I have answered for you – Raut Darpan May 27 '17 at 05:23
-
please check and let me know – Raut Darpan May 27 '17 at 05:26
2 Answers
8
private void acknowledgementFromServer(final Message message) throws StreamManagementException.StreamManagementNotEnabledException {
if (connection != null && connection.isSmEnabled()) {
connection.addStanzaIdAcknowledgedListener(message.getStanzaId(), new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
MessageAsyncTask task = new MessageAsyncTask(packet.getStanzaId(), MSG_STATUS_SENT);
task.execute();
}
});
}
Hey you can do it like this.. call method every time you send message by passing that message as a parameter in above method
Note: Stream Management should be enabled for this to work, can be done like below:
DeliveryReceiptManager.setDefaultAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.always);
ProviderManager.addExtensionProvider(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceipt.Provider());
ProviderManager.addExtensionProvider(DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceiptRequest.Provider());

Moulesh
- 2,762
- 1
- 22
- 32
-
can you please explain me how this is going to work so that i can also get to know this – Raut Darpan May 30 '17 at 10:19
-
-
that's my async task to update status of message to sqlite.. to be more clear its just to handle the response like u can have a method also in that place.. MessageAsyncTask is not related if you dont want to save your response – Moulesh May 30 '17 at 10:25
-
can you please tell me how are you getting status of message delivered in packet> – Raut Darpan May 30 '17 at 10:26
-
in this method `@Override public void processStanza(Stanza packet)` – Raut Darpan May 30 '17 at 10:26
-
it is not for message delivery, The question is how to get sent status, i.e, How to know that the message has been sent to server. Delivery Status is when the message is received by other user.. – Moulesh May 30 '17 at 10:30
-
connection.addStanzaIdAcknowledgedListener(message.getStanzaId()... if u check this line we are adding ack listener for every message we send by passing the packet id... @Override public void processStanza(Stanza packet) and here it receives same packet id if that message has receved by server – Moulesh May 30 '17 at 10:33
-
-
-
I got the question, but what is the use of `DeliveryReceiptManager` – Raut Darpan May 30 '17 at 10:36
-
http://download.igniterealtime.org/smack/docs/latest/javadoc/ there you go its a link to smack's official doc where you can find explanation – Moulesh May 30 '17 at 10:39
-
I have gone through it, what I am asking is they have not mentioned that it is acknowldgement from server : `Provides a mechanism to listen for packets that pass a specified filter. This allows event-style programming -- every time a new stanza(/packet) is found, the processStanza(Stanza) method will be called` – Raut Darpan May 30 '17 at 10:42
-
* Add a new Stanza ID acknowledged listener for the given ID. *
* The listener will be invoked if the stanza with the given ID was acknowledged by the server. It will * automatically be removed after the listener was run. Check this..
– Moulesh May 30 '17 at 10:49 -
how to get the Message? like when I send the message using Chat class so how to get Message object – Raut Darpan Jun 01 '17 at 11:49
-
note: processStanza() this only denote that the message is send to xmpp server not the user. If the user is offline then also we will get the callback in processStanza() – Shubham AgaRwal Feb 01 '18 at 10:41
-
2
According to my knowledge I have got up to this Inteface : ReceiptReceivedListener
which is in smack 4.2
below is how I have implemented this :
private ReceiptReceivedListener receiptReceivedListener;
/**
* get DeliveryReceiptManager
*
* @return
*/
private DeliveryReceiptManager getDeliveryReceiptManager() {
if (deliveryReceiptManager == null && getConnection() != null) {
deliveryReceiptManager = DeliveryReceiptManager.getInstanceFor(getConnection());
}
return deliveryReceiptManager;
}
add Listener
getDeliveryReceiptManager().addReceiptReceivedListener(receiptReceivedListener);
Received the call back
receiptReceivedListener = new ReceiptReceivedListener() {
@Override
public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
//TODO : on recieved status of message delivery
}
};
This will help you for sure
Below is the Interface for Smack 4.2 with full details :
/**
* Callback invoked when a new receipt got received.
* <p>
* {@code receiptId} correspondents to the message ID, which can be obtained with
* {@link org.jivesoftware.smack.packet.Stanza#getStanzaId()}.
* </p>
*
* @param fromJid the jid that send this receipt
* @param toJid the jid which received this receipt
* @param receiptId the message ID of the stanza(/packet) which has been received and this receipt is for
* @param receipt the receipt
*/
void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt);

Raut Darpan
- 1,520
- 9
- 14
-
1
-
1
-
-
-
-
-
-
1
-
1How can I listen server if my message sended (Like one tick state in whatsapp) or how can I get error response if there is any error. – Hosein Kord May 27 '17 at 06:05
-
That you have to write your own logic using the ReceiptReceivedListener status that is not going to be the server part – Raut Darpan May 27 '17 at 06:06
-
-