/** * 注册用户 * @param xmppConnection * @param userName * @param password * @param attributes * @return */ public static boolean regist(XMPPConnection xmppConnection,String userName,String password,Map<String,String> attributes){ AccountManager accountManager=xmppConnection.getAccountManager(); try { if(attributes!=null){ accountManager.createAccount(userName, password, attributes); } else{ accountManager.createAccount(userName, password); } return true; } catch (XMPPException e) { e.printStackTrace(); return false; } }
/** * 注册用户 * @param xmppConnection * @param userName * @param password * @param attributes * @return */ public static boolean regist(XMPPConnection xmppConnection, String userName, String password, Map<String, String> attributes) { AccountManager accountManager = xmppConnection.getAccountManager(); try { if (attributes != null) { accountManager.createAccount(userName, password, attributes); } else { accountManager.createAccount(userName, password); } return true; } catch (XMPPException e) { Log.e("regist", e.getMessage()); e.printStackTrace(); return false; } }
@Deprecated @Override public boolean createAccount(Account account) { boolean created = false; AccountManager accountManager = this.session_.getConnection().getAccountManager(); if (accountManager.supportsAccountCreation()) { try { accountManager.createAccount(account.getId().getId(), account.getPassword()); created = true; } catch (XMPPException ex) { LOG.error("Error in creating user's account: {}", ex.getMessage(), ex); throw new XMPPFailureException(ex.getMessage(), ex.getCause()).withStreamError(new StreamError(ex.getStreamError().getCode())); } } return created; }
private void createUser() throws UnsupportedOperationException, EntityExistsException { if (status == ConnectionStatus.ONLINE) { throw new EntityExistsException("The user " + userInfo.getUsername() + " already exists."); } AccountManager manager = connection.getAccountManager(); if (!manager.supportsAccountCreation()){ setConnectionStatus(ConnectionStatus.ERROR); throw new UnsupportedOperationException("The server doesn't support account creation."); } try { manager.createAccount(userInfo.getUsername(), password); } catch (XMPPException e) { setConnectionStatus(ConnectionStatus.ERROR); switch (e.getXMPPError().getCode()){ case 409: throw new EntityExistsException("The user " + userInfo.getUsername() + " already exists.", e); case 406: throw new IllegalArgumentException("Not enough or malformed arguments to create user.", e); default: throw new UnsupportedOperationException("The user couldn't be created.", e); } } }
@Override protected Boolean doInBackground(String... params) { Log.d(TAG, "Xmpp login task"); jid = params[0]; password = params[1]; Log.d(TAG, "jid " + jid + " server " + server); int port = -1; if (params.length > 2) { server = params[2]; } if (params.length > 3) { if (!TextUtils.isEmpty(params[3])) { port = Integer.parseInt(params[3]); } } Connection connection = prepareConnection(jid, server, port); try { connection.connect(); AccountManager accountManager = new AccountManager(connection); accountManager.createAccount(StringUtils.parseName(jid), password); } catch (XMPPException e) { Log.e(TAG, "Unable to create account", e); exception = e; return false; } finally { connection.disconnect(); } return true; }