• asmack xmpp 获取离线消息


    原文:http://plplum.blog.163.com/blog/static/31032400201503015345948/

    注意事项:

    1、登录前要将状态设置为离线:

    ConnectionConfiguration connectionConfig = new ConnectionConfiguration(192.168.1.82, 5222, "");
    connectionConfig.setSendPresence(false);
    ASmackMainActivity.connection = new XMPPConnection(connectionConfig);

    2、接收完离线数据后,要将离线数据清除:

    offlineManager.deleteMessages();

    3、最后要将用户状态设置为在线。

    ConnectionConfiguration connectionConfig = new ConnectionConfiguration(192.168.1.82, 5222, "");
    connectionConfig.setSendPresence(false);
    ASmackMainActivity.connection = new XMPPConnection(connectionConfig);

    connection.login(用户名,密码);

    OfflineMessageManager offlineManager = new OfflineMessageManager(ASmackMainActivity.connection);
            Iterator<org.jivesoftware.smack.packet.Message> it = offlineManager.getMessages();
                while(it.hasNext()){
                    org.jivesoftware.smack.packet.Message message = it.next();
                    Log.e(TAG, "收到离线消息, Received from 【" + message.getFrom() + "】 message: " + message.getBody());
                }
                //删除离线消息
                offlineManager.deleteMessages();
                //将状态设置成在线
                Presence presence = new Presence(Presence.Type.available);
                ASmackMainActivity.connection.sendPacket(presence);

  • 相关阅读:
    Oracle导入导出命令
    深入理解JSP/Servlet Session会话管理机制
    Weblogic domain密码的重置方法
    RPC关键要点
    Ubuntu如何配置Telnet服务器
    Win7如何解决telnet不是内部或外部命令!
    Linux系统下的文件权限
    虚拟机系统ubuntu安装VMWare Tools
    SQL模糊查询 LIKE
    Ubuntu下安装SSH
  • 原文地址:https://www.cnblogs.com/shihaiming/p/5945446.html
Copyright © 2020-2023  润新知