I am using asmack library for my chat application.I am using below described code for getting messagecount:
ServiceDiscoveryManager manager = ServiceDiscoveryMan
GTalkSMS is good example for every basic operation using Asmack lib , below is the small example code i took form GTalkSMS project to get offline messages.
public static void handleOfflineMessages(XMPPConnection connection, Context ctx)throws Exception {
OfflineMessageManager offlineMessageManager = new OfflineMessageManager(connection);
if (!offlineMessageManager.supportsFlexibleRetrieval()) {
Log.d("Offline messages not supported");
return;
}
if (offlineMessageManager.getMessageCount() == 0) {
Log.d("No offline messages found on server");
} else {
List msgs = offlineMessageManager.getMessages();
for (Message msg : msgs) {
String fullJid = msg.getFrom();
String bareJid = StringUtils.parseBareAddress(fullJid);
String messageBody = msg.getBody();
if (messageBody != null) {
Log.d("Retrieved offline message from " +messageBody);
}
}
offlineMessageManager.deleteMessages();
}
}