I am new to asmack and openfire, looked at the working answer a lot, but could not find it anywhere. How to get offline messages when logging into my asmack account?
I used the following code:
configure(ProviderManager.getInstance());
ConnectionConfiguration connConfig = new ConnectionConfiguration(HOST, PORT);
connConfig.setSendPresence(false);
connection = new XMPPConnection (connConfig);
try {
connection.connect();
} catch (XMPPException ex) {
setConnection(null);
}
try {
connection.login(username, password);
try {
OfflineMessageManager offlineManager = new OfflineMessageManager(
connection);
Iterator<org.jivesoftware.smack.packet.Message> it = offlineManager
.getMessages();
System.out.println(offlineManager.supportsFlexibleRetrieval());
System.out.println("Number of offline messages:: " + offlineManager.getMessageCount());
Map<String,ArrayList<Message>> offlineMsgs = new HashMap<String,ArrayList<Message>>();
while (it.hasNext()) {
org.jivesoftware.smack.packet.Message message = it.next();
System.out
.println("receive offline messages, the Received from [" + message.getFrom()
+ "] the message:" + message.getBody());
String fromUser = message.getFrom().split("/")[0];
if(offlineMsgs.containsKey(fromUser))
{
offlineMsgs.get(fromUser).add(message);
}else{
ArrayList<Message> temp = new ArrayList<Message>();
temp.add(message);
offlineMsgs.put(fromUser, temp);
}
}
offlineManager.deleteMessages();
} catch (Exception e) {
Log.e("CATCH","OFFLINE");
e.printStackTrace();
}
Presence presence = new Presence(Presence.Type.available);
connection.sendPacket(presence);
setConnection(connection);
} catch (XMPPException ex) {
setConnection(null);
}
, , Openfire . ( ). , , , . . . 0 , . mysql db, . , , , . , . - , .