0

我正在使用这种方法来获取用户帐户,它工作正常。现在我想将它存储为一个变量,我必须打印用户帐户。我该怎么做?

 private String getFirstAccount() {
            Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+
            Account[] accounts = AccountManager.get(HomeScreen.this).getAccounts();

            for (Account account : accounts) {
                if (emailPattern.matcher(account.name).matches()) {
                    String possibleEmail = account.name;

                    return possibleEmail;
                }
            }
            return null;
        }

例如:如果我得到三个用户帐户,我想将三个帐户存储在一个变量中并打印它。

4

1 回答 1

2
        ArrayList<Account> tempList = new ArrayList<Account>();
        for (Account account : accounts) {
            if (emailPattern.matcher(account.name).matches()) {
                templist.add(account.name);
            }
        }
        System.out.println(tempList);
        return tempList; //Returning an empty list is better than returning null
于 2013-10-01T07:37:03.440 回答