2017-07-28 71 views
0

在windows和smack debbuger上的Gajim客戶端返回這種類型的節,與xmpp規範中的相同。Smack android傳入onStanza與調試器不同

<message id='aeb213' to='[email protected]/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="[email protected]" to="[email protected]"> 
     <body>Hail to thee</body> 
     </message> 
    </forwarded> 
    </result> 
</message> 

尚未就沾染了onStanza它返回一個:

<message to="[email protected]/chamber" from="[email protected]/chamber"> 
    <result xmlns="urn:xmpp:mam:0"> 
    <body>Hail to thee</body> 
    <stanza-id/> 
    <delay/> 
    <archived/> 
    <data/> 
    </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); 
     } 
} 

回答

1

屬於XEP-0280 在SMACK中,它是一個實驗性功能。 你需要額外的庫在你的build.gradle

dependencies { 
    compile "org.igniterealtime.smack:smack-android-extensions:4.2.0" 
} 

在你做任何事情與SMACK,你必須初始化實驗功能:

new ExperimentalInitializer().initialize(); 

順便說一句,供應商是一個插件類節處理程序 如果您想在客戶端和服務器之間使用自定義節。 您必須編寫自己的提供程序來將其解析爲消息對象下的擴展元素。 看看ProviderManager。

+0

我升級到4.2.0,它解決了這個問題,因爲新增了mam支持和它的提供者。 但很好的瞭解定製提供商 – Jan