There is an issue that I am facing while sending Images through XMPP.Below is the code snippet that i have done. I don't know what is wrong with the code .
Message msg = new Message(emailId, Message.Type.chat);
ImageTransferExtension transfer = new ImageTransferExtension();
transfer.setImageName(mImageUri.getEncodedPath());
transfer.setUserRecipient(emailId);
msg.addExtension(transfer);
And here is the ImagesTransferExtension code snippet
EDIT :
public class ImageTransferExtension implements PacketExtension {
private String userRecipient;
private String ftpUrl;
private String httpUrl;
private String id;
private String typeOfMessage;
private String fieldName;
private String duration;
@Override
public String getElementName() {
// TODO Auto-generated method stub
return "x";
}
@Override
public String getNamespace() {
// TODO Auto-generated method stub
return "jabber:client";
}
@Override
public String toXML() {
StringBuilder builder = new StringBuilder();
builder.append("<" + getElementName() + " xmlns=\"" + getNamespace()
+ "\">");
if (ftpUrl != null) {
builder.append("<ftpUrl>").append(ftpUrl).append("</ftpUrl>");
}
if (httpUrl != null) {
builder.append("<httpUrl>").append(httpUrl).append("</httpUrl>");
}
if (typeOfMessage != null) {
builder.append("<typeOfMessage>").append(typeOfMessage)
.append("</typeOfMessage>");
}
if (fieldName != null) {
builder.append("<fieldName>").append(fieldName)
.append("</fieldName>");
}
if (duration != null) {
builder.append("<duration>").append(duration).append("</duration>");
}
builder.append("</" + getElementName() + ">");
return builder.toString();
}
public String getUserRecipient() {
return userRecipient;
}
public void setUserRecipient(String userRecipient) {
this.userRecipient = userRecipient;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
I don't know what to pass in the Namespace and the Element. I went through the document but found no solution.
You can use any name and namespace for your custom packets, but XML stream of your outgoing packets should be valid and well-formed XML document. In your example I see unbound ftpurl, httpurl, imageName nodes. Any good XML/XMPP parser will throw error, because your stream is not well-formed. Common practice is - wrap all you custom nodes in one top-level node and define namespace, like this:
This will cause XML parser to treat all your custom XML nodes as they come from "my:image:transfer" namespace and XML stream will be valid.
In the context of your "Image transfer extension" - you are trying to reinvent "Out-of-Band" XMPP File Transfer, which has well-known XMPP Extension - http://xmpp.org/extensions/xep-0066.html
Packets with OOB extension look like that:
Smack PacketExtension for this type of payload should look like:
This is not far from your implementation, but chances where other XMPP clients understand your "Image Transfer" are growing.