0

When I receive the message, the body is null, but the system not. And if the body has no child, the received message of body won't be null. I don't know the reason. The method and the system log is:

//========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){}
BeyelerStudios
  • 4,243
  • 19
  • 38
thisColor
  • 13
  • 2

1 Answers1

0

The smack RECV is the actual packet received.

The one that print out by packet.toXML() is the result after parsers. So, it is mostly that the mp3 xml element has not been parsed by ExtensionElementProvider and so the body cannot be built back by the toXML function of Message.

Similar question has been asked and answered before. e.g. How to get custom attribute value from an XMPP XML message?

One comment, it is simpler to add an extension outside the body element instead of modifying within the body element.

Community
  • 1
  • 1
pny_hk
  • 121
  • 2