0

In Android, how can I tell if the user has configured this device to send/receive emails using Gmail.

A device that is so configured receives Gmail messages in the notifications tray and will see Gmail listed as a synched item in the Settings/Accounts/Google screen. I'm looking for a programmatic way of accessing this boolean piece of information.

Jo Jo
  • 7,245
  • 5
  • 34
  • 49

3 Answers3

1

Try this:

Account[] accounts = accountManager.getAccountsByType("com.google");

it will work only for google accounts. You can use getAccounts() instead getAccountsByType(), now accounts will be a list of all the sync accounts. You can easily extract your desired account using accounts.name and accounts.type

Virag Brahme
  • 2,062
  • 1
  • 20
  • 32
  • 1
    Thanks, this gets much of what I need, but unfortunately an Account.name and Account.type do not actually tell me whether or not the device is setup to do Gmail specifically. For that information, it appears one needs to query the 'feature' (see other answer on this post for more info). – Jo Jo Dec 10 '13 at 09:16
1

You can make use the question asked here use AccountManager.getAccounts or AccountManager.getAccountsByType to get a list of all account names on the device. Fortunately, for certain account types (including com.google) and refer this link too

Community
  • 1
  • 1
insomniac
  • 11,146
  • 6
  • 44
  • 55
  • Thanks, this gets much of what I need, but unfortunately an Account object does not actually tell me whether or not the device is setup to do Gmail specifically. For that information, it appears one needs to query the 'feature' (see other answer on this post for more info). – Jo Jo Dec 10 '13 at 09:19
1

I got some help from this SO post: What features are supported by Android's Google accounts authenticator?.

So I used this magic incantation and it seems to work:

AccountManager.getAccountsByTypeAndFeatures("com.google", new String[]{"service_mail"}, ...);

If the resulting array has a non-zero length, then the user is logged in to Gmail.

Community
  • 1
  • 1
Jo Jo
  • 7,245
  • 5
  • 34
  • 49