我要发
<消息ID =qm5Dx-8
为=ABC
TYPE =聊天
从=ABC
MSGTYPE =2
msgTimeStamp =1413971599039
作品尺寸=18 MB
fileHeight =300
fileWidth =300
缩略图=ABC
mediaURL =
serverMediaURL =XYZ
isFromMe =1
状态=1><身体GT;图片< /身体GT;<请求的xmlns =瓮:XMPP:收据/>< /消息>
的方式,我构建自定义消息是:
公共类MyCustomMessage扩展消息{
公共MyCustomMessage(){
超();
}
公共MyCustomMessage(字符串,类型类型){
超(于类型);
}
私人字符串MSGTYPE;
私人字符串msgTimeStamp;
私人字符串isFromMe;
私人字符串状态;
私人字符串mediaURL;
私人字符串serverMediaURL;
私人字符串的文件大小;
私人字符串fileHeight;
私人字符串fileWidth;
私人字符串缩略图;
@覆盖
公共toxml用于字符串(){
串XMLMessage = super.toXML();
串XMLMessage1 = XMLMessage.substring(0,XMLMessage.indexOf(>中));
串XMLMessage2 = XMLMessage.substring(XMLMessage.indexOf(>中));
如果(this.msgType!= NULL){
XMLMessage1 + =MSGTYPE = \+ this.msgType +\;
}
如果(this.msgTimeStamp!= NULL){
XMLMessage1 + =msgTimeStamp = \+ this.msgTimeStamp +\;
}
如果(this.fileSize!= NULL){
XMLMessage1 + =文件大小= \+ this.fileSize +\;
}
如果(this.fileHeight!= NULL){
XMLMessage1 + =fileHeight = \+ this.fileHeight +\;
}
如果(this.fileWidth!= NULL){
XMLMessage1 + =fileWidth = \+ this.fileWidth +\;
}
如果(this.thumbnail!= NULL){
XMLMessage1 + =缩略图= \+ this.thumbnail +\;
}
如果(this.mediaURL!= NULL){
XMLMessage1 + =mediaURL = \+ this.mediaURL +\;
}
如果(this.serverMediaURL!= NULL){
XMLMessage1 + =serverMediaURL = \+ this.serverMediaURL +\;
}
如果(this.isFromMe!= NULL){
XMLMessage1 + =isFromMe = \+ this.isFromMe +\;
}
如果(this.status!= NULL){
XMLMessage1 + =状态= \+ this.status +\;
}
返回XMLMessage1 + XMLMessage2;
}
//所有这些领域的二传手吸气剂..
}
然后,在SmackableImplement类添加所需的字段后,即时调用的 mXMPPConnection.sendPacket(customMessage);
但中号未接收到任何数据包。我的连接是调用此方法后是封闭的每次。我已经经历了很多教程走了,但无法找到任何解决办法...告诉我,其中M是错误的。
解决方案啪肯定有一个更好的方式使用XML比这种方法与修改字符串重新presentation工作。这将破坏严重时,任何包含或任何需要被转义为属性的其他字符。
您要自定义的有效载荷添加到邮件作为一个单独的XML元素在消息中,而不是在消息的属性。您的XML应该是这样的:
<消息ID =qm5Dx-8=ABC型=聊天,从=ABC>
<身体GT;图片< /身体GT;
<请求的xmlns =瓮:XMPP:收据/>
<数据的xmlns =HTTP:// bstkaal /自定义/数据
MSGTYPE =2
msgTimeStamp =1413971599039
作品尺寸=18 MB
fileHeight =300
fileWidth =300
缩略图=ABC
mediaURL =
serverMediaURL =XYZ
isFromMe =1
状态=1/>
< /消息>
I want to send
<message id="qm5Dx-8"
to="abc"
type="chat"
from="abc"
msgType="2"
msgTimeStamp="1413971599039"
fileSize="18 MB"
fileHeight="300"
fileWidth="300"
thumbnail="abc"
mediaURL=""
serverMediaURL="xyz"
isFromMe="1"
status="1"><body>Image</body><request xmlns='urn:xmpp:receipts'/></message>
The way i am constructing the custom message is :
public class MyCustomMessage extends Message{
public MyCustomMessage(){
super();
}
public MyCustomMessage(String to, Type type){
super(to, type);
}
private String msgType ;
private String msgTimeStamp ;
private String isFromMe ;
private String status ;
private String mediaURL ;
private String serverMediaURL ;
private String fileSize ;
private String fileHeight ;
private String fileWidth ;
private String thumbnail ;
@Override
public String toXML() {
String XMLMessage = super.toXML();
String XMLMessage1 = XMLMessage.substring(0, XMLMessage.indexOf(">"));
String XMLMessage2 = XMLMessage.substring(XMLMessage.indexOf(">"));
if (this.msgType != null) {
XMLMessage1 += " msgType=\"" + this.msgType + "\"";
}
if (this.msgTimeStamp != null) {
XMLMessage1 += " msgTimeStamp=\"" + this.msgTimeStamp + "\"";
}
if (this.fileSize != null) {
XMLMessage1 += " fileSize=\"" + this.fileSize + "\"";
}
if (this.fileHeight != null) {
XMLMessage1 += " fileHeight=\"" + this.fileHeight + "\"";
}
if (this.fileWidth != null) {
XMLMessage1 += " fileWidth=\"" + this.fileWidth + "\"";
}
if (this.thumbnail != null) {
XMLMessage1 += " thumbnail=\"" + this.thumbnail + "\"";
}
if (this.mediaURL != null) {
XMLMessage1 += " mediaURL=\"" + this.mediaURL + "\"";
}
if (this.serverMediaURL != null) {
XMLMessage1 += " serverMediaURL=\"" + this.serverMediaURL + "\"";
}
if (this.isFromMe != null) {
XMLMessage1 += " isFromMe=\"" + this.isFromMe + "\"";
}
if (this.status != null) {
XMLMessage1 += " status=\"" + this.status + "\"";
}
return XMLMessage1 + XMLMessage2;
}
// Setters Getters of all these fields..
}
Then after adding required fields in SmackableImplement class, i m calling mXMPPConnection.sendPacket(customMessage);
but m not receiving any packet. my connections is being closed everytime after calling this method. I have gone through many tutorials but couldnt find any solution...tell me where m mistaken.
解决方案Smack surely has a better way to work with XML than this approach with modifying the string representation. This will break badly when anything contains a "
or any of the other characters that need to be escaped as an attribute.
You have to add custom payloads to messages as a separate XML element within the message, not as attributes on the message. Your XML should look like:
<message id="qm5Dx-8" to="abc" type="chat" from="abc">
<body>Image</body>
<request xmlns='urn:xmpp:receipts'/>
<data xmlns='http://bstkaal/custom/data'
msgType="2"
msgTimeStamp="1413971599039"
fileSize="18 MB"
fileHeight="300"
fileWidth="300"
thumbnail="abc"
mediaURL=""
serverMediaURL="xyz"
isFromMe="1"
status="1" />
</message>
上一篇:该getActionBar方法返回null方法、getActionBar、null
下一篇:E / OpenGLRenderer:而在genymotion使用毕加索和okhttp从GradienCache错误获取MAX_TEXTURE_SIZE毕加索、而在、错误、genymotion