Android Smack XMPP:原始响应和节监听器响应不一样

时间:2017-02-03 09:14:14

标签: java android xmpp smack

目前,我正在使用Android应用进行聊天。我使用的是Android Smack库4.1.5版。现在我有一个问题是获取Message Archive的响应结果。原始响应和我的监听器之间有不同的结果。谢谢你的帮助!

原始回复

D/SMACK: RECV (0): <message from='hazmi@xmpp.mationable.com' to='fahmi@xmpp.mationable.com/Smack'><result xmlns='urn:xmpp:mam:tmp' id='1486108894062450'><forwarded xmlns='urn:xmpp:forward:0'><message xmlns='jabber:client' from='fahmi@xmpp.mationable.com/Smack' to='hazmi@xmpp.mationable.com' xml:lang='en' id='209' type='chat'><body>test</body><thread>9461d01b-ef76-4ab1-a619-0360fbb4dcdf</thread></message><delay xmlns='urn:xmpp:delay' from='xmpp.mationable.com' stamp='2017-02-03T08:01:34.062Z'/></forwarded></result></message>

Stanza听众

D/FromStanza: <message to='fahmi@xmpp.mationable.com/Smack' from='hazmi@xmpp.mationable.com'><result xmlns='urn:xmpp:mam:tmp'><body>test</body><delay></delay><thread>e849c5e8-d4ee-4faf-a95c-43773eaf30a3</thread></result></message>

这是我的代码

    final IQ iq = new IQ("query") {
            @Override
            protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
                xml.append(" xmlns='urn:xmpp:mam:tmp'>");
                xml.element("with", recipient);

                return xml;
            }
        };

        iq.setType(IQ.Type.get);
        iq.setFrom(connection.getUser());
        iq.setTo(recipient);
// set the type
// send the request
        try {
            connection.sendStanza(iq);
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        }

        ProviderManager.addIQProvider("query", "urn:xmpp:mam:tmp", new IQProvider<IQMessageArchive>() {
            @Override
            public IQMessageArchive parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException, SmackException {
                // Start parsing loop
                int eventType = parser.next();
                outerloop:
                while (eventType != XmlPullParser.END_DOCUMENT) {
                    switch (eventType) {
                        case XmlPullParser.START_TAG:
                            String elementName = parser.getName();

                            break;
                        case XmlPullParser.END_TAG:
                            if (parser.getDepth() == 3) {
                                break outerloop;
                            }
                            break;
                    }
                    eventType = parser.next();
                }
                return null;
            }
        });

connection.addAsyncStanzaListener(new StanzaListener() {
    @Override
    public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
        Log.d("FromStanza", ""+packet.toXML());

    }
}, new StanzaFilter() {
    @Override
    public boolean accept(Stanza stanza) {
        return true;
    }
});

0 个答案:

没有答案