Get Android Google Account

You can get the android google account from a device using the AccountManager like this:

Account[] accounts = AccountManager.get(this).getAccounts();
for (Account account : accounts) {
 
// TODO: Check possibleEmail against an email regex or treat
 
// account.name as an email address only for certain account.type values.
 
String possibleEmail = account.name;
 
...
}

source:  http://stackoverflow.com/questions/2112965/how-to-get-the-android-devices-primary-e-mail-address

You might want to check on account.type to match “com.google” since many other synchronisation accounts exists on a regular device. Think of facebook and weather synchronisation.

Also this requires the GET_ACCOUNTS permission set to your manifest:


        

Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait