For this you need to edit 2 classes of Smack 4.1
- Stanza class in (org.jivesoftware.smack.packet)
- PacketParserUtils class in (org.jivesoftware.smack.util)
1. Stanza class
Define your custom attribute (nick)
private String nick = null;
Define Getter and Setters
public String getNick() {
return this.nick;
}
public void setNick(String paramString) {
this.nick = paramString;
}
Edit Stanza Constructor
protected Stanza(Stanza p) {
//add this line
nick = p.getNick();
}
Edit addCommonAttributes method
protected void addCommonAttributes(XmlStringBuilder xml) {
//add this line
if(getNick()!= null)
xml.optAttribute("nick", getNick());
}
2. PacketParserUtils class
Edit parseMessage method
public static Message parseMessage(XmlPullParser parser)
throws XmlPullParserException, IOException, SmackException {
//add this line
message.setNick(parser.getAttributeValue("", "nick"));
}
Now you can simply set nick and send message as follows
Message message = new Message();
message.setType(Message.Type.chat);
message.setStanzaId("123");
message.setTo(number);
message.setNick("SHAYAN");
try {
connection.sendStanza(message);
} catch (NotConnectedException e) {
}