How to get user own email addresses stored in the device?

岁酱吖の 提交于 2019-12-10 23:12:41

问题


I need to retrieve all the email addresses of the user, stored in the device (not the email addresses of his friends, but his OWN email addresses). For example, if I've three mail addresses geltrude@gmail.com, geltry@yahoo.co.uk and cippalippa@hotmail.com, i'm looking for a method that returns an array (or similar) with these three Strings: ["geltrude@gmail.com", "geltry@yahoo.co.uk", "cippalippa@hotmail.com"]. Any idea?

Edit: I'd like to get the email addresses stored in the "me" contact on the device, plus the own email addresses stored in the default mail app and in the gmail client app (that are the default used apps, I think). Thanks in advance. G.


回答1:


Most of those addresses are maintained by email clients which don't have content providers to get at them.

If your goal is to use the address list to select the return address for an outgoing email, that doesn't fit the Android way of doing things. Your application should announce that it wants to send an email by throwing out a properly-outfitted ACTION_SEND intent. Whatever application ultimately services it may give the user a choice about which account and return address to use in sending it.


Addendum:

The default email client has a content provider called content://com.android.email.provider/account that you shouldn't or can't use because:

  • It's undocumented.
  • Its manifest requires that apps wanting to use it have the com.android.email.permission.ACCESS_PROVIDER permission.
  • That permission has a protectionLevel of signatureOrSystem, which restricts grants to apps stored in the system image or signed with the same key as those in the system image. Your application is unlikely to fall into either of those categories.

Other things to be aware of:

  • There is no guarantee that a given device will have support for email.
  • Email on a device may be serviced by a third-party email client (e.g., K9, SEVEN, Touchdown, MailDroid or others) which maintains its own account database and likely doesn't expose it.


来源:https://stackoverflow.com/questions/5126207/how-to-get-user-own-email-addresses-stored-in-the-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!