简单的smack jabber程序需要很长时间才能在android上进行连接

时间:2018-12-12 14:06:11

标签: java android smack

使用smack jabber library 4.3.1,我的android程序需要84秒才能连接,这相当长。我have seen a discussion in a forum遇到了类似的问题,但它影响了SMACK的早期版本。

我在做什么错了?

下面是代码用来连接的提示。

                XMPPTCPConnectionConfiguration cc= XMPPTCPConnectionConfiguration.builder()
                        .setCompressionEnabled(true)
                        .setUsernameAndPassword("smackuser","ilovesmack")
                        .setXmppDomain("xmpp.jp")
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.required)
                        .build();
                connection=new XMPPTCPConnection(cc);
                connection.addConnectionListener(MainActivity.this);
                connection.connect();
                connection.login();

1 个答案:

答案 0 :(得分:1)

我发现了问题。 SMACK jabber使用minidns和minidns has a recently fixed bug on android 8。我通过使用下面的代码解决了这个问题。感谢@Flow

//////////////////////smack///////////////////////////////////////
implementation "org.igniterealtime.smack:smack-android-extensions:4.3.1"
implementation "org.igniterealtime.smack:smack-experimental:4.3.1"
implementation "org.igniterealtime.smack:smack-tcp:4.3.1"
implementation 'de.measite.minidns:minidns-hla:0.2.4'//added this

增加了minidns依赖性

import org.minidns.dnsserverlookup.android21.AndroidUsingLinkProperties;
AndroidUsingLinkProperties.setup(context);//add this
cc=XMPPTCPConnectionConfiguration.builder()
                        .setCompressionEnabled(true)
                        .setUsernameAndPassword(username,password)
                        .setXmppDomain(domain)
                        .build();
                xmpptcpConnection=new XMPPTCPConnection(cc);
                xmpptcpConnection.addConnectionListener(this);
                xmpptcpConnection.connect();
                xmpptcpConnection.login();