As can see in asmack documentation when you receive one Chat type Message in processMessage() method from the MessageListener of Chat, I should to send back this message using Chat.sendMessage() to notify the message reception.
But in my chat implementation, I don´t use ChatManager when open one to one chat, I have an Service and Listener to do those things.
In Service I have an PacketListener to receive, and I am trying to do the send back message properly, as I can see in asmack documentation, but it don´t work.
this.xmppChat.addPacketListener(new PacketListener() {
@Override
public synchronized void processPacket(Packet packet) {
Message message = (Message) packet;
if (message.getType() == Message.Type.chat) {
Log.i("XMPP_SERVICE",
String.format("Mensaje recibido de %s",
message.getFrom()));
// Rest of code implementation...
// At the end try to send back message to notify reception.
XMPPService.this.xmppChat.sendMessage(new Message(message.getBody()));
}
}
}, new PacketTypeFilter(Message.class));
The XMPPService.this.xmppChat.sendMessage(Message message) method:
public boolean sendMessage(Message message) {
Log.i("XMPP_INFO", "Enviando el mensaje");
try {
this.xmppManager.getConnection().sendPacket(message);
Log.i("XMPP_INFO", "Enviado el mensaje");
return true;
} catch (Exception ex) {
Log.e("XMPP_ERROR", ex.getMessage());
return false;
}
}
What wrong I am doing?, and How can I to fix it?
Best regards and thank you in advance.