Smack API 用户搜索
我尝试在基于 Smack-API 的 jabber 客户端上实现用户搜索。它可以使用以下方式创建用户:
AccountManager manager = conn.getAccountManager();
manager.createAccount(usename,password);
但是,我需要添加一个功能,在创建帐户之前首先搜索“现有”用户,但是我找不到任何直接的方法来做到这一点。任何人都可以给我提示吗?
谢谢。
I'm try to implement a user search on top of my working Smack-API based jabber client.It can create user using:
AccountManager manager = conn.getAccountManager();
manager.createAccount(usename,password);
However I need to add a functionality that will first search for "existing" user before it creates the account, but I can't find any straightforward way to do it. Anyone can provide me hints?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
显然,我们需要的只是捕获 XMPPException 中的错误代码 409,因为如果用户存在,createAccount 就会抛出异常。
Apparently what's needed is just to catch the error code 409 in the XMPPException, as createAccount throws exception if user exist.
尽管您实际上不再需要您所请求的功能(根据您自己的答案),但我无论如何都会回答原始问题以供将来参考。
Smack 中有一个名为 UserSearchManager 的类可以用于此目的。
Although you don't actually need the functionality you requested any more (according to your own answer), I will answer the original question anyway for future reference.
There is a class called UserSearchManager in Smack that can be used for this purpose.
最简单的方法是以用户身份登录一次,不发送状态信息。一般来说,我们会尝试找到在无法以用户身份登录的情况下回答此问题的所有方法,并消除它们,以帮助防止垃圾邮件。
Easiest way is to log in as the user once, without sending presence. In general, we try to find all of the ways you could answer this question without having the ability to log in as the user, and eliminate them, in order to help prevent spim.