※マニフェストには、
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
を追加する。
// 端末に設定されているGmailAccountの取得
private String[] getGmailAccounts() {
ArrayList<String> accountsInfo = new ArrayList<String>();
Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
String name = account.name;
String type = account.type;
Log.d(LOGTAG, "DBG:" + account.toString());
if(type.equals("com.google")){  // googleアカウントタイプなら
accountsInfo.add(name);
}
}
String[] result = new String[accountsInfo.size()];
accountsInfo.toArray(result);
return result;
}
0 件のコメント:
コメントを投稿