powered by Jive Software

Can't receive offline message after login,and set perence available before.smack version 4.3.4,openfire version:4.4.2

public String getOfflineMessage() {
    String jsonStr = "";
    try {
        OfflineMessageManager offlineManager = new OfflineMessageManager(mConnection);
        //获取离线消息
        List<Message> messageList = offlineManager.getMessages();
        if (null != messageList && messageList.size() > 0) {
            List<MessageModel> list = new ArrayList<MessageModel>();
            for (Message message : messageList) {
                String fromId = "";
                String content = message.getBody();
                String from = message.getTo().toString();
                if (from.contains("/")) {
                    fromId = from.split("/")[0];
                    if (FlutterXmppPlugin.DEBUG) {
                        Log.d(TAG, "The real jid is :" + fromId);
                        Log.d(TAG, "The message is from :" + from);
                        Log.d(TAG, "The message  :" + content);
                    }
                } else {
                    fromId = from;
                }

                MessageModel messageModel = new MessageModel(fromId, content);
                list.add(messageModel);
            }
            Gson gson = new Gson();
            jsonStr = gson.toJson(list);
        } else {
            Log.d(TAG, "getOfflineMessage() list is empty");
        }
        //特别说明,这条代码的意思是获取离线消息的数量,我也不知道为啥只有加了这句才可以真正删除离线记录,
        //否则就一直删不掉,老重复接收重复的离线消息记录
        Log.d(TAG, "getOfflineMessageCount:" + offlineManager.getMessageCount());
        //获取后删除离线消息记录
        offlineManager.deleteMessages();
        //设置在线,只有设置了在线状态,才可以监听在线消息,否则监听都无效
        Presence presence = new Presence(Presence.Type.available);
        mConnection.sendStanza(presence);
    } catch (Exception e) {
        Log.d(TAG, "getOfflineMessage()" + e.toString());
    }
    Log.d(TAG, "getOfflineMessage() jsonStr:" + jsonStr);
    return jsonStr;
}

Again, please make an effort creating bug reports.

  • What exactly are you trying to do?
  • What do you expect to happen?
  • What does actually happen?
  • Please share a stanza log.

Take a look at this page to learn how to create better bug reports.

add conf.setSendPresence(false);
now it work;
thank you!