android收到的消息体是null

时间:2015-09-06 03:54:19

标签: android xmpp asmack

当我收到消息时,正文为空,但系统没有。如果身体没有孩子,收到的身体信息将无效。我不知道原因。方法和系统日志是:

//========this  is  system log==========
09-06 11:33:56.385: D/SMACK(6685): 11:33:56 上午 RCV  (1116678480):
<message  
type="chat" from="13905076418@xmpp.zznnet.cn/kafei" 
to="8613800000008@xmpp.zznnet.cn">
<body>
    <mp3 id="278" 
         title="me" 
         img="http://59.57.240.170:40081//upload/201507/21/201507211559595666.jpg"   
         tag="GEM"/>
</body>
<mfile xmlns="xmpp.zznnet.cn"><mtype>mp3</mtype></mfile>
</message>


//========this  is my  log============
 09-06 11:33:56.405: I/System.out(6685): xml: 
 <message to="8613800000008@xmpp.zznnet.cn" from="13905076418@xmpp.zznnet.cn/kafei"    
 type="chat">
   <body>nullnull</body>
   <mfile xmlns="xmpp.zznnet.cn">
 <mtype>mp3</mtype></mfile>
</message>

//This is part of the received code
mPacketListener = new PacketListener() {
        public void processPacket(Packet packet) {
            try {           
                if (packet instanceof Message) {
                    Message msg = (Message) packet;
                    String chatMessage = msg.getBody();
                    System.out.println("xml:" +packet.toXML());}}
            catch(Exception e){}

1 个答案:

答案 0 :(得分:0)

smack RECV是收到的实际数据包。

由packet.toXML()打印出来的是解析器之后的结果。 因此,大多数情况下,mp3 xml元素尚未被ExtensionElementProvider解析,因此无法通过Message的toXML函数构建正文。

之前已经提出并回答了类似的问题。例如 How to get custom attribute value from an XMPP XML message?

一条评论,在body元素之外添加扩展而不是在body元素中修改更简单。