How to read custom attributes of xmpp message tag in android?

99封情书 提交于 2019-12-04 05:01:13

问题


The xml that i need to receive is :

<message id="qm5Dx8" to="adsfxcv" type="chat"from="adsf"
 msgType="2"
 thumbnail="randomThumbnail"
 serverMediaURL="random"
 isFromMe="1"
 status="1"><body>Image</body><request xmlns='urn:xmpp:receipts'/></message>

Message is being sent by MyCustomMessage extends Message class.

In my message listener, Where i need to get the packet is :

            public void processPacket(Packet packet) {
            String recivedPacket = packet.toXML();
            try {
                if (packet instanceof MyCustomMessage) {
                    MyCustomMessage msg = (MyCustomMessage) packet;
                    ....

But I am receiving only id,to,type and from in message tag. And the instance of packet is also of Message and it says , cannot cast packet to message. plz guide me how can i receive my desired packet.


回答1:


You can't. Also you should never extend the Message or Presence class.

Never add custom values to specified stream element attributes (e.g. a new value for the type attribute of messages), and never add new attributes to top level elements (like you did with msgType, msgTimeStamp and so on).

This has the potential to break things! Don't do it. See also "XEP-0134: XMPP Design Guidelines § 2.1 XMPP is Sacred". That's why it's not possible in Smack. Instead, use a custom extension element, like xnyhps showed in his example (the data element). See also "RFC 6120 § 8.4 Extended Content" Those are called PacketExtension's in Smack.

See also this answer and question.



来源:https://stackoverflow.com/questions/26516386/how-to-read-custom-attributes-of-xmpp-message-tag-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!