3
votes

In my chat application I want to get the offline messages when the user signs in ( if anybody has sent him messages) . I am getting the notifications when the user is in online state and not able to get the messages after the user signs in back. I have checked the xmpp log cat also. I am able to read the offline messages there but i am unable to notify the user his/her ofline mesages.

Here is the listener which I am using in onStart of my service ( service is immediately started on user logon)

PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
        final PacketCollector collector = connection.createPacketCollector(filter);
        connection.addPacketListener(new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
                // TODO Auto-generated method stub
                //notification(packet.getFrom());
                packet = collector.nextResult();
                Message message = (Message)packet;
                senderName = packet.getFrom();

                int alphaPOS = senderName.indexOf("@");
                String subSenderName = senderName.substring(0,alphaPOS); 


                if(UserChatActivity.checkPresence==false){

                    notificationforChat(subSenderName+": "+message.getBody(),packet.getFrom().toString());

               }

            }

        }, filter);

    }

This works fine when user is online. But I want that once the user logs in he should be notified his messages

Thanks

2

2 Answers

2
votes

You have to make sure that your XMPP server supports XEP 0136, the message archiving extension of XMPP.

That same extension will explain how you can retrieve the archived messages.

For ejabberd, you can install and configure the mod_archive extension for this. It will save the messages to a SQL backend.

0
votes

Change the filter to filter messages of type Message.class not chat messages because offline messages are not of type chat (I don't think)

PacketFilter filter = new PacketTypeFilter(Message.class);

See how you go.

Actually re reading your question; are you saying that you can see the offline message being received in LogCat but not on the screen? Where are you logging the messages being received?