public boolean registerAccount(String name, String password, Map<String, String> attr) {
try {
// getConnection();
new Thread(new Runnable() {
@Override
public void run() {
try {
connection.connect();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
org.jivesoftware.smackx.iqregister.AccountManager manager = org.jivesoftware.smackx.iqregister.AccountManager.getInstance(connection);
manager.sensitiveOperationOverInsecureConnection(true);
if (attr == null) {
try {
manager.createAccount(name, password);
System.out.println("hello1");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
} else {
try {
System.out.println("hello2");
manager.createAccount(name, password, attr);
Thread.sleep(1000);
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("完成操作");
}
}).start();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
最近在学smack,开始添加用户,老是返回500的错误,后来将用户名改为英文便解决了