amarikp / asmack

Automatically exported from code.google.com/p/asmack
Other
0 stars 0 forks source link

Getting offline messages #67

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When i am trying to get offline chat,i got classcast excpetion.
I am using below code for getting offline 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);

                    }

My logcat output is
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(ServiceDiscoveryMan
ager.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)

I am using asmack-jse-buddycloud-2010.12.11.jar.

What is problem in that i cant able to find.I had check out source code but in 
this i cant find classes.so i can lookout line at which i got exception

Original issue reported on code.google.com by chirag.s...@indianic.com on 14 Sep 2011 at 11:10

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I know what the problem is. DiscoverInfo is derived from IQ. Code under 
ServiceDiscoveryManager:discoverInfo is trying to Downcast IQ to DiscoverInfo. 
Downcasting IQ to discoverInfo is causing java.lang.ClassCastException: 
org.jivesoftware.smack.util.PacketParserUtils$2

Original comment by Lopez.Sa...@gmail.com on 14 May 2012 at 11:26

GoogleCodeExporter commented 8 years ago
I had same issue while retrieving offline messages from openfire server. I had 
also trying it with Offlinemessagemanager class but it doesn't work for me. So 
I found a solution on that and its finely working on my side.

I did register a simple message listener with the connection object immediate 
after log in and able to receive offline messages from server.

Original comment by che...@kratin.co.in on 30 Mar 2013 at 7:29

GoogleCodeExporter commented 8 years ago
Dear Chetan, 

I am a newbie in Andriod programming and I am now creating an app for XMPP. 
The OfflineMessageManager class doesn't work for me either. 
It simple throws NullPointerException. 
I wonder if you could help me solve it. 
Thank you. 

My code: 
OfflineMessageManager offlineManager = new OfflineMessageManager(connection);
// Log.i("Offline Message", "supportsFlexibleRetrieval = " + 
offlineManager.supportsFlexibleRetrieval());                    
Iterator<Message> it = offlineManager.getMessages();
while (it.hasNext()) {
    Message m = it.next();
    String fromName = m.getFrom();
    Date currentDate = new Date();
    String text = m.getBody() + " (offline)";
    // ...
}
offlineManager.deleteMessages();

Priere

Original comment by Priere...@gmail.com on 6 Jun 2013 at 3:05

GoogleCodeExporter commented 8 years ago
Hello Priere,

As mention in my comment, you should register simple message listener immediate 
after login code, then you should able to get offline message coming from 
server.

As you mentioned in your code , you are using OfflineMessageManager class and 
try to retrieve offline message from that. But when I go with this approach it 
doesn't work for me.

Hope so this answer helps you.
You can feel free to contact me on my mail address for any related queries.

Thanks.   
Have happy coding. 

Original comment by che...@kratin.co.in on 6 Jun 2013 at 4:41

GoogleCodeExporter commented 8 years ago
add this...in your code before ServiceDiscoveryManager, here pm is the Provider 
Manager Instance....

 pm.addIQProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageRequest.Provider());
        //  Offline Message Indicator
        pm.addExtensionProvider("offline","http://jabber.org/protocol/offline", new OfflineMessageInfo.Provider());

its working in my case...:)

Original comment by shrey.sh...@divergentsl.com on 13 Feb 2014 at 7:16