powered by Jive Software

Asmack 4.0 , I can't get offline message

some code:

OfflineMessageManager offlineManager = new OfflineMessageManager(

connection);

int count = offlineManager.getMessageCount());

List messages = offlineManager.getMessages();

the count=3,but messages is[]. why?

can anyone help one

config.setSendPresence(false) before U login,otherwise U will not get offline message

1 Like

thanks for your answer,but i had add the method(config.setSendPresence(false) ) before i login, i can’t still get offline messgae !the message count i can get,but the messages list is empty! i can’t understand. my english is poor,don’t care!

//Can’t get offline messages for asmack4.0.2

//对于asmack4.0.2不能获取离线消息

// The method can get offline messages now,messageCollector must be created before send packet,the problem is wrong code order

//现在下面这个方法可以获取离线消息,messageCollector一定要在发送包之前创建,是代码顺序的问题,修改后如下:

public List getMessages() throws NoResponseException, XMPPErrorException, NotConnectedException {

List messages = new ArrayList();

OfflineMessageRequest request = new OfflineMessageRequest();

request.setFetch(true);

PacketCollector messageCollector = connection.createPacketCollector(packetFilter);//before

connection.createPacketCollectorAndSend(request).nextResultOrThrow();//after

// Collect the received offline messages

Message message = (Message) messageCollector.nextResult();

while (message != null) {

messages.add(message);

message = (Message) messageCollector.nextResult();

}

// Stop queuing offline messages

messageCollector.cancel();

return messages;

}

Reported as SMACK-589 and fixed in latest 4.0.3 SNAPSHOTS.