powered by Jive Software

aSmack Listener & IQ Provider Problems

Hi guys.the provider executing the listener does not work.

Register listeners;

mGetListenPackets(xmppconn,new PacketTypeFilter(IQ.class));
mGetListenPackets(xmppconn,new PacketTypeFilter(Presence.class));
mGetListenPackets(xmppconn,new PacketTypeFilter(org.jivesoftware.smack.packet.Message.class));
ProviderManager.getInstance().addIQProvider(Ping.ELEMENT, Ping.NAMESPACE, new PingProvider());
ProviderManager.getInstance().addIQProvider(Provider.element_name, Provider.namespace,new Provider());

i catch custom iq packets but listener does not work.

@Override
public IQ parseIQ(XmlPullParser xpp) throws Exception {
          int eventType = xpp.getEventType();
          PvCommand pvCommand = null;
          String currentTag = null;
          while (eventType != XmlPullParser.END_DOCUMENT) {
                     if (eventType == XmlPullParser.START_TAG) {
                              currentTag = xpp.getName();
                              if (xpp.getName().equalsIgnoreCase("pvcommand")) {
                                         pvCommand = new PvCommand();
                               }
                              } else if (eventType == XmlPullParser.END_TAG) {
                                        currentTag = null;
                                        if (xpp.getName().equalsIgnoreCase("pvcommand")) {
                                                  // custom iq send dispatcher method
                                                  iqPacketDispatcher(pvCommand);
                                                  pvCommand = null;
                                        }
                              } else if (eventType == XmlPullParser.TEXT) {                                         if (currentTag != null) {
                                                  if (currentTag.equalsIgnoreCase("sendClassName")) {
                                                            pvCommand.setSendClassName(xpp.getText());
                                                  } else if (currentTag.equalsIgnoreCase("sendMethodName")) {
                                                            pvCommand.setSendMethodName(xpp.getText());
                                                  } else if (currentTag.equalsIgnoreCase("spvcommand")) {
                                                            pvCommand.setSpvCommand(xpp.getText());
                                                  }
                                        }
                              }
                              eventType = xpp.next();
                    }                     return null;
          }

i add break in provider.listener worked.but server send error packet.

help me please.

Don’t look for the END_DOCUMENT event, that is the close of the session. You are only parsing the specific element with the provider, so your provider must exit when the END_TAG is reached for that element.