LoginSignup
10
10

More than 5 years have passed since last update.

Androidで携帯に設定されてるGmailを取得する。

Last updated at Posted at 2013-05-10

パーミッションはandroid.permission.GET_ACCOUNTSが必要。
マルチアカウントなので複数返ってくることもあります。

ArrayList<String> mailList = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccounts();
    for (Account account : accounts) {
    String type = account.type;
    if (type.equals("com.google")) {
        String mail = account.name;
        mailList.add(mail);
    }
}

これでもよかった

ArrayList<String> mailList = new ArrayList<String>();
accounts = AccountManager.get(this).getAccountsByType("com.google");
for (Account account : accounts) {
        mailList.add(account.name);
}
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10