我在使用 XMPP 时遇到了很多麻烦,我对它很陌生,我发现的所有示例都已经有一个帐户可以连接并执行操作。
我的问题涉及新用户。没有帐户的人需要能够自己注册然后登录。但据我了解,您首先需要创建连接,然后才能创建用户。因此,如果没有帐户,您就无法创建帐户。
我读过的一些链接:
https://code.google.com/p/lxmppd/issues/detail?id=328
https://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/
http://www.igniterealtime.org/builds/smack/dailybuilds/documentation/connections.html
所以基本上,我需要在没有用户登录的情况下创建连接。然后创建一个用户并使用该用户登录。
所以我发现了这个:
但 AccountManager 类似乎已过时或其他原因,因为我无法在同一路径中找到它。 (http://www.igniterealtime.org/builds/smack/docs/4.0.6/javadoc/org/jivesoftware/smack/AccountManager.html)
所以问题是:如何创建一个新帐户然后使用它登录(从新用户的角度来看)?
如果有一个小代码 fragment 或某个来源的链接,我们将不胜感激。
编辑1: 我已经到了这一点:
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setServiceName("jabber.org")
.setHost(AppConfig.XMPP_HOST)
.setPort(Integer.parseInt(AppConfig.XMPP_PORT))
.build();
XMPPConnection connection = new XMPPTCPConnection(config);
现在我需要实例化一个 AccountManager 对象,但它在 smack 4.1 中不可用
我正在尝试遵循这个示例:How to create an account from Smack 4.1
尽管我读到它应该在 smackx 中。我在 smackx 中唯一能找到的是:
import org.jivesoftware.smackx.debugger.android.AndroidDebugger
最佳答案
创建帐户的方法是首先连接到服务器,然后初始化帐户创建。本质上,您创建一个可以在其中创建帐户的连接,然后继续创建所述帐户。我是这样做的:
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setServiceName(SERVICE_NAME)
.setHost(HOST_NAME)
.setPort(5222)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(conf);
connection.connect(); // Here we create the connection
// Now we create the account:
AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.createAccount(username, password);
// The account has been created, so we can now login
connection.login(username, password);
所以我们首先初始化连接,创建帐户,然后登录。希望这会有所帮助
关于java - XMPP注册新用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30261703/