I need to send “custom IQ request”.
Sample IQ request:
<iq xmlns=‘xep:history’ from=’#username@#serverchathost’ id=’#id’ to=’#serverchathost’ type=‘recents’>
I use smack 4.2.0-beta2 for Android.
How to do it?
I need to send “custom IQ request”.
Sample IQ request:
<iq xmlns=‘xep:history’ from=’#username@#serverchathost’ id=’#id’ to=’#serverchathost’ type=‘recents’>
I use smack 4.2.0-beta2 for Android.
How to do it?
Hi
you can do it with creting custom iq packet using below code
import java.util.HashMap;
import java.util.Map;
import org.jivesoftware.smack.packet.IQ;
public class IQBuilder extends IQ {
private Map<String, String> attributes = new HashMap<String, String>();
private boolean remove = false;
private String namespace = “xep:history”;
public String getNamespace() {
return namespace;
}
public void setNamespace(String namespace) {
this.namespace = namespace;
}
public Map<String, String> getAttributes() {
return attributes;
}
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
public boolean isRemove() {
return remove;
}
public void setRemove(boolean remove) {
this.remove = remove;
}
@Override
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append("<iq xmlns=’"+namespace+"’ ");
if (attributes != null && attributes.size() > 0 && !remove) {
for (String name : attributes.keySet()) {
String value = attributes.get(name);
buf.append(name).append("=");
buf.append("’"+value+"’");
}
} else if (remove) {
buf.append("");
}
// Add packet extensions, if any are defined.
buf.append(getExtensionsXML());
buf.append("");
return buf.toString();
}
}
and create custom iq packet where you want using following code
IQBuilder iq = new IQBuilder();
attribute.put(“from”, “from”);
attribute.put(“to”, “to”);
attribute.put(“id”, “id”);
attribute.put(“type”, “recents”);
iq.setAttributes(attribute);
iq.setNamespace(“xep:historry”);
System.out.println(iq.getChildElementXML());
hope this will help you…
how to receive IQ come from server?
in android?