Dan Fabulich Dan Fabulich - 1 year ago 109
Android Question

Getting Android owner's email address nicely

I want to allow the user to provide me their email address without typing it in. Ideally, there'd be a text field where the user could either type an email address or push a button to autofill it.

In an earlier question, Roman Nurik suggests using an AccountManager to handle this, but that requires my app to use the GET_ACCOUNTS privilege; my app could then access all of the user's accounts on the device, including their Facebook/Twitter accounts. That permission seems way too broad for what I want.

Is there a nicer way to handle this that doesn't require granting my app such a heavy duty permission?

Answer Source

Indeed, not only can't you do this without GET_ACCOUNTS, the information you want only exists in the user's (Google) account data.

On my Sprint phone, the 'owner' address sprint assigns is myusername@sprintpcs.com, and that can be seen using getprop from a shell. But that's not my primary email address, or even one I ever use/check. What you want is my gmail address, and that's stored in the Android account data.

Actually, you want one of the two — which is another reason you need GET_ACCOUNTS. If you're going to ask for my email address, you need to let me select among the two @gmail.com accounts I have configured on the device. I know which one is my 'preferred' one (although even that's contextual), but AFAIK neither is considered by the system to be more 'primary' or 'default' than the other.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download