smack 4.1.4开发安卓的注册方法

//smack 4.1.4版本的注册
public static IQ regist(String accounts,String password) throws SmackException.NotConnectedException {
    Map attributes = new HashMap();
    attributes.put("username", accounts);
    attributes.put("password", password);
    Registration reg = new Registration(attributes);
    reg.setType(IQ.Type.set);
 
  
    reg.setTo(XmppConnection.getConnection().getServiceName());

   StanzaFilter filter = new AndFilter(new PacketIDFilter(
            reg.getPacketID()), new PacketTypeFilter(
            IQ.class));
    PacketCollector collector = XmppConnection.getConnection().
            createPacketCollector(filter);
    XmppConnection.getConnection().sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration
            .getDefaultPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();// 停止请求results(是否成功的结果)

    return result;
}
参考自以下文章
http://blog.csdn.net/mashihao123/article/details/51689777

你可能感兴趣的:(技术分享)