【问题标题】:New User in XMPP?XMPP 的新用户?
【发布时间】:2018-06-08 00:08:31
【问题描述】:

我已经建立了到 XMPP 服务器的连接。我的问题是,如果有一个聊天室并且新用户想加入,我应该使用 Smack 类以下的用户来注册它吗?

AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(username, password);

它会创建新用户加入 Room 还是会创建新用户到主服务器。请帮忙理解。谢谢!

【问题讨论】:

    标签: android xmpp smack groupchat


    【解决方案1】:

    提到的类和方法createAccount在服务器上创建新帐户,您可以从 Github 代码中读取:

    https://github.com/igniterealtime/Smack/blob/master/smack-extensions/src/main/java/org/jivesoftware/smackx/iqregister/AccountManager.java

    代码:

    /**
         * Creates a new account using the specified username and password. The server may
         * require a number of extra account attributes such as an email address and phone
         * number. In that case, Smack will attempt to automatically set all required
         * attributes with blank values, which may or may not be accepted by the server.
         * Therefore, it's recommended to check the required account attributes and to let
         * the end-user populate them with real values instead.
         *
         * @param username the username.
         * @param password the password.
         * @throws XMPPErrorException
         * @throws NoResponseException
         * @throws NotConnectedException
         * @throws InterruptedException
         */
        public void createAccount(Localpart username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException  {
            // Create a map for all the required attributes, but give them blank values.
            Map<String, String> attributes = new HashMap<>();
            for (String attributeName : getAccountAttributes()) {
                attributes.put(attributeName, "");
            }
            createAccount(username, password, attributes);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-24
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 2012-05-02
      • 2012-01-14
      • 1970-01-01
      相关资源
      最近更新 更多