2
votes

I have offline messages option enabled in the openfire server.But I'm unable to get offline messages

User A is online ,User B is online ,in this case I'm able to get messages.

Now User B Turned off his WiFi(Note : User A waited till the user B Session completely killed in the server )

now User A send a message to User B

in this case I'm able to see the message in the openfire offline table.

Now User B Comes online again server is sending the message to user B as the server come to know that User B is online (Message disappeared from offline messages table ).

But User B is not going to receive that message.

connection.login(userName, userPwd,  UiUtility.getMyPhoneNO());
PacketFilter filter = new PacketTypeFilter(org.jivesoftware.smack.packet.Message.class);
packetListener =new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;


if (message.getBody() != null) {
  String fromName = StringUtils.parseBareAddress(message
  .getFrom());
  Log.i("XMPPClient", "Got text [" + message.getBody()
  + "] from [" + fromName + "]");
   }
  }
  };
   connection.addPacketListener(packetListener, filter);

Again after successful login im able to chat normally.But I wonder why those offline messages are missing ? .My PacketListener unable to catch those offline messages .Please Help me

3
Hi @Phanindra . Have you found any solution . i have also stuck in same situation .Deepak Rathore

3 Answers

0
votes

Asmack is depreceated. Use Smack. An Open Source XMPP Client Library written in Java for JVMs and Android. Add the following lines to your gradle file:

compile 'org.igniterealtime.smack:smack-android:4.1.3'
compile 'org.igniterealtime.smack:smack-tcp:4.1.3'
compile 'org.igniterealtime.smack:smack-extensions:4.1.3'
0
votes

The problem is easy to be solved. Before making connection with the XMPP server just register providers using ProviderManager class provided by ASmack library.

If this can't solve ur problem visit ur local server and search for offline messages, and select the option ALWAYS STORE setting the storage limit to be 1000 kb. It is 100 kb by default. Hope this works.

0
votes

After lot struggle, I have resolved the issue. In your openfire admin page, go to "client settings" and reduce the idle time from 360sec (by default) to 1 sec(may be). Only then when you disconnected from Internet, it can detect that you are offline and preserve rest of the messages as OFFLINE.

@Override public void onNetworkConnectionChanged(boolean isConnected) {

    if(isConnected){
        new Thread() {

            public void run() {
                try {
                    XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
                    builder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
                    builder.setUsernameAndPassword("phone", "admin");
                    builder.setSendPresence(true);
                    builder.setServiceName(<Service name>);
                    builder.setHost(<Host name>);
                    builder.setResource("Test");
                    builder.setDebuggerEnabled(true);
                    Presence presence = new Presence(Presence.Type.available);
                    presence.setStatus("Available");
                    connection = new XMPPTCPConnection(builder.build());
                    connection.connect();
                    connection.login();
                    Presence presence123 = new Presence(Presence.Type.available);
                    presence123.setStatus("Available");
                    try {
                        connection.sendStanza(presence123);
                    } catch (SmackException.NotConnectedException e) {
                        e.printStackTrace();
                    }
                    StanzaFilter filter = new AndFilter(new StanzaTypeFilter(Message.class));
                    PacketListener myListener = new PacketListener()
                    {
                        public void processPacket(Stanza stanza)
                        {
                            retrieveMessage(stanza,userType);
                        }
                    };
                    connection.addPacketListener(myListener, filter);
                    try {
                        connection.sendStanza(presence);
                    } catch (SmackException.NotConnectedException e) {
                        e.printStackTrace();
                    }

                } catch (SmackException | XMPPException | IOException e) {
                    e.printStackTrace();
                }


                //return connection.isConnected();
            }

        }.start(); 

The above is working fine and able to retrieve the offline messages. The method "retrieveMessage(stanza,userType);" is used to process the incoming message and update the Adapter. Make sure to send the Presence as "Available" when you reconnect. Please let me know if there are still any issues.