public static boolean renameAccount(String newName, Account account,
            AccountManager accountManager, Context context) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            accountManager.renameAccount(account, newName, null, null);
        } else {
            Account newAccount = new Account(newName, account.type);
            Bundle userData = AccountsHelper.buildBundle(
                    AccountsHelper.getUserName(context, account),
                    AccountsHelper.getUserMail(context, account),
                    AccountsHelper.getUserAvatar(context, account),
                    AccountsHelper.getUrl(context, account)
            );

            String authToken = accountManager.getUserData(account, AccountManager.KEY_AUTHTOKEN);
            userData.putString(AccountManager.KEY_AUTHTOKEN, authToken);

            removeAccount(account, accountManager);

            accountManager.addAccountExplicitly(newAccount, null, userData);
            accountManager.setAuthToken(newAccount, account.type, authToken);
            LoginActivity.configureSyncFor(newAccount);
        }

        return true;
    }
Get configured account

@param context
@return account or null if none
app/src/main/java/com/github/pockethub/android/accounts/AccountUtils.java