I am looking for a way to look through all of an Android phones contacts and build a list of accounts that are Google accounts.
Now the obvious solution is to just look for emails that end with "@gmail.com". However this doesn't work for all cases. If your contacts have a company email that uses gmail, then your email will end in "@companyURL.ext" and not "@gmail.com" even though they have a valid gmail account.
Is this at all possible to do?
I assume you mean that you want contacts (i.e. other people) who happen up have email addresses where the mail hosted by Google, as opposed to Google accounts that belong to the phone's user. (Just checking to be paranoid, but the second case is actually easy). Then not really. Or at least I can see no practical way.
Consider this case. I give you my email foo@bar.com. You enter that in your contacts. Today I'm self hosting. Next week I move my domain to Google Apps and let Google host my mail. Nothing on the phone will change. The only visible change to the outside world is that I would have updated the MX records on my DNS zone file to point to Google. I suppose you could take the domains, do a DNS query for MX records and decide if mail server(s) are google servers. Shy of that, there's nothing that exists to say my mail is hosted at Google. But I don't think that's a very practical answer at all.
Also consider the case where I have multiple mail aliases that forward to my account. I might have them associated with my Google account, in which case I can log in at Google and get Gmail with them. But not even the MX record will give that away, even though mail to them will end up in my Gmail account.
In my case, I have email addresses I use that use both of those patterns.