Rah*_*rma 13 android xmpp smack
我在这里使用了很棒的帖子设置了一个xmpp服务器和android客户端...我在xmpp服务器中设置了一些预先定义的用户,我可以使用这些凭据登录.
现在,从我的应用程序,我想通过Android客户端注册为xmpp服务器的新用户.任何人都可以建议我如何实现这一目标......任何帮助都将受到赞赏...... !!!
也许我迟到了,但如果你使用的是最新的smack-android:4.1.0,你可以试试下面的代码创建XMPPTCPConnectionConfiguration的connection对象,并注册一个用户:
// Creating a connection
XMPPTCPConnectionConfiguration connConfig =
XMPPTCPConnectionConfiguration.builder()
.setHost("myHost.com") // Name of your Host
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setPort(5222) // Your Port for accepting c2s connection
.setDebuggerEnabled(true)
.setServiceName("myServiceName")
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(connConfig);
try {
// connecting...
connection.connect();
Log.i("TAG", "Connected to " + connection.getHost());
// Registering the user
AccountManager accountManager = AccountManager.getInstance(connection);
accountManager.sensitiveOperationOverInsecureConnection(true);
accountManager.createAccount(username, password); // Skipping optional fields like email, first name, last name, etc..
} catch (SmackException | IOException | XMPPException e) {
Log.e("TAG", e.getMessage());
xmppClient.setConnection(null);
}
Run Code Online (Sandbox Code Playgroud)
我通过开发一个将用户名和密码作为 post 参数的网络服务来解决这个问题。如果我们发布用户名和密码,网络服务就会注册一个新用户。
我发现这相当简单,而不是从应用程序注册......
| 归档时间: |
|
| 查看次数: |
12643 次 |
| 最近记录: |