Хорошо, ребята, простой вопрос, но очень важный для меня.
Итак, другой клиент Android отправляет это xml msg:
<message
id='6ymdM-19'
to='[email protected]/smack'
type='chat'>
<subject>normal</subject>
<received xmlns='urn:xmpp:receipts' id='HVgQw-5'/>
</message>
и мой слушатель примерно такой:
private class MsgListener implements ChatStateListener {
/**
* Constructor.
*/
public MsgListener() {
}
@Override
public void processMessage(Chat chat, org.jivesoftware.smack.packet.Message message) {
String xmlMessage = message.toXML();
Log.v(TAG, "XML Chat: "+xmlMessage);
// getExtension namespace try urn:xmpp:receipts
if(xmlMessage.contains("<request xmlns=")) {
Log.d(TAG, "new chat message arrive! reply with RECEIVED!");
replyReceived(message);
} else if(xmlMessage.contains("<received xmlns=")) {
Log.d(TAG, "RECEIVED notification arrived!");
PacketExtension statusExtension =
message.getExtension("urn:xmpp:receipts");
Log.d(TAG, "Extension name: "+statusExtension.getElementName());
Log.d(TAG, "Extension XML: "+statusExtension.toXML());
Log.d(TAG, "Extension string: "+statusExtension.toString());
}
....
....
....
}
в этом случае я хочу получить значение атрибута «id» внутри тега «полученного» элемента. но то, что я получил в своем журнале, выглядит так:
RECEIVED notification arrived!
D/ChatAdapter(320): Extension name: received
D/ChatAdapter(320): Extension XML: <received xmlns="urn:xmpp:receipts"></received>
D/ChatAdapter(320): Extension string:
org.jivesoftware.smack.packet.DefaultPacketExtension@44f10430
Итак, как я могу получить «HVgQw-5» ??
ОБНОВЛЕНИЕ
На самом деле есть что-то странное... Я получил XML-согласие от моей отладки SMACK следующим образом:
<
D/SMACK(320): 05:40:28 PM RCV (1156991856): message id="6ymdM-19"
to="[email protected]/Smack" from="[email protected]/Smack"
type="chat"><subject>
D/SMACK(320): 05:40:28 PM RCV (1156991856): normal</subject><thread>cr0900</thread>
**<received xmlns="urn:xmpp:receipts" id="HVgQw-5"/>**<active
xmlns="http://jabber.org/protoc
D/SMACK(320): 05:40:28 PM RCV (1156991856): ol/chatstates"/></message>
Но когда я выполняю message.toXML, он просто распечатывается так:
XML Chat: <message id="6ymdM-19" to="[email protected]/Smack" from="[email protected]/Smack" type="chat"><subject>normal</subject><thread>cr0900</thread>**<received xmlns="urn:xmpp:receipts">**</received><active xmlns="http://jabber.org/protocol/chatstates" /></message>
Почему это происходит? почему я пропускаю "id"?