I am working on a project, and I have to fill the EditText automatically with the user\'s primary email, I am considering primary email as the email that associated with google
I agree with @driodev. but I have done it with a different approach. just copy and paste the code... I might be answering this question a bit late but I guarantee this will be helpful to many in future. In fact, I think we can get any account id that is used in the android device just by changing the string in getAccount("com.example"). Here is the code.
String User_EmailId = getEmiailID(getApplicationContext());
private String getEmailID(Context context) {
AccountManager accountManager = AccountManager.get(context);
Account account = getAccount(accountManager);
if (account == null) {
return null;
} else {
return account.name;
}
}
private static Account getAccount(AccountManager accountManager) {
Account[] accounts = accountManager.getAccountsByType("com.google");
Account account;
if (accounts.length > 0) {
account = accounts[0];
} else {
account = null;
}
return account;
}
`