XMPP——Smack[1]离线消息实现

注意事项:

1、登录前要将状态设置为离线:

ConnectionConfiguration connectionConfig = new ConnectionConfiguration(192.168.1.82, 5222, "");
connectionConfig.setSendPresence(false);
ASmackMainActivity.connection = new XMPPConnection(connectionConfig);

2、接收完离线数据后,要将离线数据清除:

offlineManager.deleteMessages();


3、最后要将用户状态设置为在线。


ConnectionConfiguration connectionConfig = new ConnectionConfiguration(192.168.1.82, 5222, "");
connectionConfig.setSendPresence(false);
ASmackMainActivity.connection = new XMPPConnection(connectionConfig);
connection.login(用户名,密码);

OfflineMessageManager offlineManager = new OfflineMessageManager(ASmackMainActivity.connection);
        Iterator it = offlineManager.getMessages();
            while(it.hasNext()){
                org.jivesoftware.smack.packet.Message message = it.next();
                Log.e(TAG, "收到离线消息, Received from 【" + message.getFrom() + "】 message: " + message.getBody());
            }
            //删除离线消息
            offlineManager.deleteMessages();
            //将状态设置成在线
            Presence presence = new Presence(Presence.Type.available);
            ASmackMainActivity.connection.sendPacket(presence);


转自:http://blog.csdn.net/zhangzhikaixinya/article/details/8727237


你可能感兴趣的:(xmpp,IM)