我一直在尝试向客户端发送自定义iq,但收到的错误称为"不可用的服务"。我在发送时遇到的错误类型是"取消"。我看了对于这种错误类型的解决方案,并发现它与不使用完整的jid有关,但在我的代码中你可以看到,我正在使用完整的jid。有人可以帮我这个吗?
这是我正在使用的代码。
public class CustomIQ extends IQ {
String mMyData;
public CustomIQ(String mydata) {
super("list", "test:namespace");
this.mMyData=mydata;
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
xml.rightAngleBracket();
xml.element("myData", mMyData);
return xml;
}
}
Custom provider class
public class CustomIQProvider extends IQProvider {
@Override
public Element parse(XmlPullParser parser, int initialDepth) throws Exception {
String data="nothing";
// Start parsing loop
int eventType = parser.next();
outerloop:
while (eventType != XmlPullParser.END_DOCUMENT) {
switch (eventType) {
case XmlPullParser.START_TAG:
String elementName = parser.getName();
if ("myData".equals(elementName)) {
data = parser.nextText();
}
break;
case XmlPullParser.END_TAG:
if (parser.getDepth() == 3) {
break outerloop;
}
break;
}
eventType = parser.next();
}
return new CustomIQ(data);
}
}
Finally i send packet like this.
enter code here
CustomIQ myIq = new CustomIQ("test data");
myIq.setType(IQ.Type.get);
myIq.setTo("aman@attriaman-android/Smack");
try {
mConnection.sendPacket(myIq);
} catch (Exception exp) {
exp.printStackTrace();
}
我做错了什么?提前谢谢!