donderdag 10 maart 2011

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
  // as an email address only for certain account.type values.
  String possibleEmail =;

You might want to check on account.type to match "" 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:
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>

Geen opmerkingen:

Een reactie posten