2017-07-28 5 views
0

Windows上のGajimクライアントとsmack debbugerは、この種のスタンザを返します。これはxmppスペックのものと同じです。スマートアンドロイド着信オンスタンザはデバッガとは異なります

まだ上
<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

それは実験的な機能ですが、SMACKでXEP-0280 に属します。ちなみに

new ExperimentalInitializer().initialize(); 

、プロバイダはプラグインのようなスタンザです: あなたがSMACKを持つことを行う前に、実験的な機能を初期化する必要があり、あなたのbuild.gradleに

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

を追加ライブラリが必要ハンドラー クライアントとサーバーの間にカスタマイズされたスタンザを使用する場合。 メッセージオブジェクトの下にある拡張要素に解析するために、独自のプロバイダを作成する必要があります。 ProviderManagerを見てください。

+0

私は4.2.0にアップグレードし、これは新しく追加されたmamサポートとそのプロバイダのためにこれを解決しました。 カスタムプロバイダについて知っておきたいこと – Jan

関連する問題