Capture events

Events Litener.

You can capture all MQTT chat events using a mqttchatListener :

mqttchatListener listener= new mqttchatListener() {
@Override
public void onLoadComplete() {
Log.i(Tag,"MQTT Chat load complete");
}
@Override
public void onUserPresenceUpdate(int i, String s, boolean b, boolean b1, String s1) {
Log.i(Tag,"User presence update : userId:"+i +"; new status:"+s+" ;voice capacity:"+b +" ;video capacity:"+b1+"; timestamp:"+s1);
}
@Override
public void onSendMessage(int i, Message message) {
Log.i(Tag,"Logged user send message to userId :"+i +"; message:"+message.toString());
}
@Override
public void onAckMessage(int i, Ack ack, Message message) {
Log.i(Tag,"Logged user received Ack from server for message sent to userId :"+i +"; ack :"+ack.toString()+"; message:"+message.toString());
}
@Override
public void onRejectMessage(int i, String s, Message message) {
Log.i(Tag,"Logged user has sent message to userId:"+i+"; message was rejected by server because of :"+s+"; and message content :"+message.toString());
}
@Override
public void onIncomingMessage(int i, Message message) {
Log.i(Tag,"Logged user received new message from userId:"+i+"; message content:"+message.toString());
}
@Override
public void onUserTyping(int i, boolean b) {
Log.i(Tag,"A user userId:"+i+" is currently typing to logged user; is typing :"+b);
}
@Override
public void onReadingMessage(int i, int i1, String s) {
Log.i(Tag,"A user userId:"+i+"; is reading message id:"+i1+" ; reading date :"+s);
}
@Override
public void onNotReadMessagesCountUpdate(int i) {
Log.i(Tag,"Number of unread messages is changed for logged user, new number is :"+i);
}
@Override
public void onError(int i, String s) {
Log.e(Tag,"MQTTCHAT error code :"+i+";message :"+s);
}
};

To add listener to MQTT chat:

/** add new MQTTCHAT listener **/
Mqttchat.getmInstance().addMqttchatListener(listener);

And to remove listener :

/** remove MQTTCHAT listener **/
Mqttchat.getmInstance().removeMqttchatListener(listener);