简体   繁体   English

缺少脱机邮件asmack(Android)

[英]Missing Offline messages asmack (Android)

I have offline messages option enabled in the openfire server.But I'm unable to get offline messages 我在openfire服务器中启用了离线消息选项。但是我无法获取离线消息

User A is online ,User B is online ,in this case I'm able to get messages. 用户A在线,用户B在线,在这种情况下,我能够收到消息。

Now User B Turned off his WiFi(Note : User A waited till the user B Session completely killed in the server ) 现在,用户B关闭其WiFi(注意:用户A等到用户B会话在服务器中被完全杀死)

now User A send a message to User B 现在,用户A向用户B发送一条消息

in this case I'm able to see the message in the openfire offline table. 在这种情况下,我可以在openfire离线表格中看到该消息。

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 ). 现在,用户B再次联机,因为服务器知道用户B联机(服务器从脱机消息表中消失了),服务器正在向用户B发送消息。

But User B is not going to receive that message. 但是用户B将不会收到该消息。

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 。我的PacketListener无法捕获那些脱机消息。请帮助我

Asmack is depreceated. Asmack被淘汰。 Use Smack . 使用Smack An Open Source XMPP Client Library written in Java for JVMs and Android. 用Java编写的针对JVM和Android的开源XMPP客户端库。 Add the following lines to your gradle file: 将以下行添加到gradle文件中:

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'

The problem is easy to be solved. 这个问题很容易解决。 Before making connection with the XMPP server just register providers using ProviderManager class provided by ASmack library. 与XMPP服务器建立连接之前,只需使用ASmack库提供的ProviderManager类注册提供程序。

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. 如果这不能解决您的问题,请访问本地服务器并搜索脱机消息,然后选择“始终存储”选项,将存储限制设置为1000 kb。 It is 100 kb by default. 默认情况下为100 kb。 Hope this works. 希望这行得通。

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). 在您的openfire管理页面中,转到“客户端设置”,并将空闲时间从360秒(默认)减少到1秒(可能是)。 Only then when you disconnected from Internet, it can detect that you are offline and preserve rest of the messages as OFFLINE. 只有这样,当您断开与Internet的连接时,它才能检测到您处于脱机状态,并将其余消息保留为OFFLINE。

@Override public void onNetworkConnectionChanged(boolean isConnected) { @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);" 方法“ 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. 如果还有任何问题,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM