Get Service is not available for offline message

I got Service -unavailable cancel error when I am trying to retrieve the offline messages.

  1. Prevent server to set presence to available: config.setSendPresence(true);

  2. Connect to the server: connection.contect();

  3. Login after connected to the server

  4. Retrieve the Offline Message:

public void dealOfflineMsg() {

try {

OfflineMessageManager offlineManager = new OfflineMessageManager(connection);

List messages = offlineManager.getMessages();

for (Message message : messages){

ChatMessage chatMessage = getChatMessage(message);, chatMessage);



Presence presence = new Presence(Presence.Type.available);


}catch (Exception e){

showToast("Offline Message Error: " + e.getLocalizedMessage());



However, it throws error ‘service-unavailable-cancel’.

How can I solve this issue?