I am using asmack library for my chat application.I am using below described code for getting messagecount:
ServiceDiscoveryManager manager = ServiceDiscoveryMan
Only use OfflineMessageManager, if you don't want to get the offline messages automatically (XEP-0013).
Otherwise just add your StanzaListener to the connection and login.
XMPPTCPConnectionConfiguration userBasicConfiguration = XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setServiceName(SERVICE_NAME)
.setHost(HOST_NAME)
.setDebuggerEnabled(false)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(PORT)
.setUsernameAndPassword(userName, password)
.build();
AbstractXMPPConnection firstUserConnection = new XMPPTCPConnection(userBasicConfiguration);
firstUserConnection.connect();
StanzaFilter filter = new StanzaTypeFilter(Message.class);
StanzaListener listener = stanza -> {
System.out.println(stanza.toString());
};
firstUserConnection.addSyncStanzaListener(listener,filter);
firstUserConnection.login();
while (!Thread.currentThread().isInterrupted()){
}
firstUserConnection.disconnect();