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;
        }

例: 3 つのユーザー アカウントを取得している場合、3 つのアカウントを変数に格納して出力したいとします。

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 に答える