이 방법을 사용하여 사용자 계정을 가져오고 잘 작동합니다. 이제 변수를 저장하고 사용자 계정을 인쇄해야합니다. 어떻게 할 수 있습니까?
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;
}
예를 들어 : 세 개의 사용자 계정이있는 경우 변수에 세 개의 계정을 저장하고 인쇄하고 싶습니다.
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
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다