asmack xmpp 获取离线消息
原文:http://plplum.blog.163.com/blog/static/31032400201503015345948/
?
注意事項:
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<org.jivesoftware.smack.packet.Message> 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);
總結
以上是生活随笔為你收集整理的asmack xmpp 获取离线消息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ifdown eth0 idup et
- 下一篇: 写自己的一个pdo数据库操作框架