java - 无法使用 smack 在 openfire 中添加新用户 - android

标签 java android xmpp openfire smack

我正在android中创建一个即时消息应用程序并尝试使用smack和xmpp的openfire服务器创建一个新用户,用户将存储在openfire数据库中但每次我运行它时,用户记录都不是显示在其中。

创建用户 Activity

 private void setConnection() {

        // Create the configuration for this new connection

        //this function or code given in official documention give an error in openfire run locally to solve this error
        //first off firewall
        //then follow my steps

        new Thread() {
            @Override
            public void run() {

                InetAddress addr = null;
                try {
                    // inter your ip4address now checking it
                    addr = InetAddress.getByName("192.168.23.150");
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }
                HostnameVerifier verifier = new HostnameVerifier() {
                    @Override
                    public boolean verify(String hostname, SSLSession session) {
                        return false;
                    }
                };
                DomainBareJid serviceName = null;
                try {
                    serviceName = JidCreate.domainBareFrom("localhost");
                } catch (XmppStringprepException e) {
                    e.printStackTrace();
                }
                XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
                        .setUsernameAndPassword("admin","kalaBOOK98")
                        .setPort(9090)
                        .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                        .setXmppDomain(serviceName)
                        .setHostnameVerifier(verifier)
                        .setHostAddress(addr)
                        .setDebuggerEnabled(true)
                        .build();
                Log.v(TAG,"connection configured");
                mConnection = new XMPPTCPConnection(config);
                        //now send message and receive message code here
                        AccountManager accountManager = AccountManager.getInstance(mConnection);
                        try {
                            Log.v(TAG,"Creating new user");
                            accountManager.createAccount(Localpart.from(userId),userPassword);
                        } catch (SmackException.NoResponseException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (XMPPException.XMPPErrorException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (SmackException.NotConnectedException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (InterruptedException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        } catch (XmppStringprepException e) {
                            Log.v(TAG,"Error in creating user"+e);
                            e.printStackTrace();
                        }
                    }

// Now we create the account:

// The account has been created, so we can now login

        }.start();
    }

每次我尝试运行它时都会出现此日志错误

日志

    2018-11-30 18:44:16.186 12186-12855/com.example.user.myapplication V/SignupActivity: connection configured
2018-11-30 18:44:16.216 12186-12855/com.example.user.myapplication V/SignupActivity: Creating new user
2018-11-30 18:44:16.218 12186-12855/com.example.user.myapplication V/SignupActivity: Error in creating userorg.jivesoftware.smack.SmackException$NotConnectedException: Client is not, or no longer, connected.
2018-11-30 18:44:16.218 12186-12855/com.example.user.myapplication W/System.err: org.jivesoftware.smack.SmackException$NotConnectedException: Client is not, or no longer, connected.
2018-11-30 18:44:16.226 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smack.tcp.XMPPTCPConnection.throwNotConnectedExceptionIfAppropriate(XMPPTCPConnection.java:354)
2018-11-30 18:44:16.226 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smack.AbstractXMPPConnection.sendStanza(AbstractXMPPConnection.java:670)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smack.AbstractXMPPConnection.createStanzaCollectorAndSend(AbstractXMPPConnection.java:769)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.createStanzaCollectorAndSend(AccountManager.java:370)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.getRegistrationInfo(AccountManager.java:366)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.getAccountAttributes(AccountManager.java:184)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at org.jivesoftware.smackx.iqregister.AccountManager.createAccount(AccountManager.java:249)
2018-11-30 18:44:16.227 12186-12855/com.example.user.myapplication W/System.err:     at com.example.user.myapplication.Login.SignupActivity$3.run(SignupActivity.java:192)

任何帮助将不胜感激提前致谢

最佳答案

如果您已经在 openfire 上创建了一个用户,那么您不需要从移动应用程序使用 AccountManager 创建它。构建 xmppTcpConnection 后,只需连接并使用新用户的凭据登录即可。

检查此链接: xmpp connection documentation

关于java - 无法使用 smack 在 openfire 中添加新用户 - android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53559918/

相关文章:

android - 如何获取重复事件的实时时间?

Android Video View - 无法播放此视频

java - XMPP 客户端不兼容

java - 如何使用 Openfire 和 XMPP 在 Android 中制作聊天机器人应用程序

XMPP:如何向服务器请求用户联系人的存在状态?

java - "Simple"Trie实现

java - 如何从指纹读取器读取数据并将其转换为java中的图像文件

android - mapFragment.getMap() 返回 null

java - "public"和 "public final"是接口(interface)字段的冗余吗?

java - 日期格式化程序产生奇怪的输出