I am using asmack library for my chat application.I am using below described code for getting messagecount:
ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverInfo info = manager.discoverInfo(null,"http://jabber.org/protocol/offline");
Form extendedInfo = Form.getFormFrom(info);
if (extendedInfo != null) {
String value = extendedInfo.getField("number_of_messages").getValues().next();
Log.e(TAG, "offline message"+value);
}
But i got exception as described below:
09-14 16:11:32.892: ERROR/AndroidRuntime(498): at com.datingapps.breaktheice.SigninScreen.coonectToChat(SigninScreen.java:393)
09-14 16:35:20.611: WARN/System.err(538): java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2
09-14 16:35:20.811: WARN/System.err(538): at org.jivesoftware.smackx.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:608)
09-14 16:35:20.811: WARN/System.err(538): at com.datingapps.breaktheice.Chat$connectionTask.doInBackground(Chat.java:286)
09-14 16:35:20.811: WARN/System.err(538): at com.datingapps.breaktheice.Chat$connectionTask.doInBackground(Chat.java:1)
09-14 16:35:20.811: WARN/System.err(538): at android.os.AsyncTask$2.call(AsyncTask.java:185)
09-14 16:35:20.811: WARN/System.err(538): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
09-14 16:35:20.821: WARN/System.err(538): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
09-14 16:35:20.821: WARN/System.err(538): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
09-14 16:35:20.821: WARN/System.err(538): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
09-14 16:35:20.821: WARN/System.err(538): at java.lang.Thread.run(Thread.java:1096)
Anybody who have implemented it with asmack or have alternate solution with smack lib, Please help me to get out of this problem.
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.
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.
Replace your code with this . I have used this code its running fine.
After Googling and searching in documentation,All i got that offlinemanager for getting offline messages.
But However it is not working in asmack or may be in smack.It always return 0 message.
Finally by seeing logs i found that each tie when i login i got lot of response from chat server which also contains offline message but with message tag not offline message tag.So I found finally
You can get offline messages from it by directly setting packet listener after just login .As i below described packet listener you have to implement after login method.
Hope it will help many to find a work around for offline message early as i invested more time to get it out.
Try replacing your code with this.
Just checking, did you configure your smack providers?
Before establishing the connection, this should be called
Without calling this, you will definitely get