Smack android传入OnTanza与调试器不同
windows和smack debbuger上的Gajim客户端返回这种节,与xmpp规范中的节相同Smack android传入OnTanza与调试器不同,android,xmpp,ejabberd,smack,Android,Xmpp,Ejabberd,Smack,windows和smack debbuger上的Gajim客户端返回这种节,与xmpp规范中的节相同 <message id='aeb213' to='juliet@capulet.lit/chamber'> <result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'> <forwarded xmlns='urn:xmpp:forward:0'> <del
<message id='aeb213' to='juliet@capulet.lit/chamber'>
<result xmlns='urn:xmpp:mam:2' queryid='f27' id='28482-98726-73623'>
<forwarded xmlns='urn:xmpp:forward:0'>
<delay xmlns='urn:xmpp:delay' stamp='2010-07-10T23:08:25Z'/>
<message xmlns='jabber:client' from="witch@shakespeare.lit" to="macbeth@shakespeare.lit">
<body>Hail to thee</body>
</message>
</forwarded>
</result>
</message>
你怎么解决这个问题?下面是代码的一些部分
public class XmppServiceSmackImpl implements XmppService, StanzaListener, ConnectionListener {
XmppServiceListener xmppServiceListener;
Logger logger = Logger.getLogger(XmppServiceSmackImpl.class.getName());
XMPPTCPConnection connection;
String password;
public XmppServiceSmackImpl(XmppServiceListener xmppServiceListener) {
this.xmppServiceListener = xmppServiceListener;
}
@Override
public void setup(String jid, String password, String authMethod, String hostname, Integer port) {
final String[] jidParts = jid.split("@");
String[] serviceNameParts = jidParts[1].split("/");
String serviceName = serviceNameParts[0];
XMPPTCPConnectionConfiguration.Builder confBuilder = XMPPTCPConnectionConfiguration.builder()
.setServiceName(serviceName)
.setUsernameAndPassword(jidParts[0], password)
.setConnectTimeout(3000)
//.setDebuggerEnabled(true)
.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
if (serviceNameParts.length>1){
confBuilder.setResource(serviceNameParts[1]);
} else {
confBuilder.setResource(Long.toHexString(Double.doubleToLongBits(Math.random())));
}
if (hostname != null){
confBuilder.setHost(hostname);
}
if (port != null){
confBuilder.setPort(port);
}
if (trustedHosts.contains(hostname) || (hostname == null && trustedHosts.contains(serviceName))){
confBuilder.setCustomSSLContext(UnsafeSSLContext.INSTANCE.getContext());
}
XMPPTCPConnectionConfiguration connectionConfiguration = confBuilder.build();
XMPPTCPConnection.setUseStreamManagementDefault(true);
XMPPTCPConnection.setUseStreamManagementResumptionDefault(true);
connection = new XMPPTCPConnection(connectionConfiguration);
// Disable automatic roster request
Roster roster = Roster.getInstanceFor(connection);
roster.setRosterLoadedAtLogin(false);
roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
connection.addAsyncStanzaListener(this, null);
connection.addConnectionListener(this);
connection.addStanzaAcknowledgedListener(this);
}
@Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
logger.log(Level.WARNING, "Received stanza: " + packet);
this.xmppServiceListener.onStanza(packet);
}
}
属于XEP-0280
在SMACK中,这是一个实验性特征。
在build.gradle中需要额外的库
dependencies {
compile "org.igniterealtime.smack:smack-android-extensions:4.2.0"
}
在使用SMACK进行任何操作之前,必须初始化实验功能:
new ExperimentalInitializer().initialize();
顺便说一下,提供者是一个类似于节处理程序的插件
当您希望在客户端和服务器之间使用自定义节时。
您必须编写自己的提供者来将其解析为Message对象下的扩展元素。
看看ProviderManager。我升级到4.2.0,它解决了这个问题,因为新添加了mam支持及其提供程序。但是了解自定义提供者很好
new ExperimentalInitializer().initialize();