我希望获得一对一聊天和群聊的聊天记录。经过一些研究后,我才知道我可以通过Message Archive Management来做到这一点。但它没有提供任何示例来将旧消息输入到Android客户端。我想从服务器获取较旧的消息聊天历史记录,但我不知道如何从xmpp服务器中提取旧消息。这里有很多关于这方面的问题,但没有得到任何适当的解决方案。到目前为止我所做的是连接并向其他用户发送消息。任何人都可以帮我从xmpp服务器获取聊天记录吗?
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("user1", "password")
.setHost(getString(R.string.domain))
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setServiceName(getString(R.string.domain))
.setPort(5222)
.setDebuggerEnabled(true) // to view what's happening in detail
.build();
XMPPTCPConnection conn1 = new XMPPTCPConnection(config);
conn1.setUseStreamManagement(true);
XMPPTCPConnection.setUseStreamManagementDefault(true);
conn1.setUseStreamManagementResumption(true);
// ReconnectionManager.getInstanceFor(this.conn1).enableAutomaticReconnection();
conn1.setPacketReplyTimeout(10000);
try {
conn1.connect();
if(conn1.isConnected()) {
Log.w("app", "conn done");
}
conn1.login();
if(conn1.isAuthenticated()) {
Log.w("app", "Auth done");
}
}
catch (Exception e) {
Log.w("app", e.toString());
}
ChatManager chatmanager = ChatManager.getInstanceFor(conn1);
Chat newChat = chatmanager.createChat("user2@"+getString(R.string.domain));
try {
newChat.sendMessage("Test Msg from user1!!!");
}
catch (SmackException.NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}