获取联系人手机android的电子邮件

时间:2011-05-04 16:00:23

标签: android

您好 我如何获取联系人的列表电子邮件? 我想在微调器中显示这个电子邮件列表。 感谢

1 个答案:

答案 0 :(得分:1)

ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
if (cur.getCount() > 0)
{
  while (cur.moveToNext())
  {
    String id = cur.getString(
                      cur.getColumnIndex(ContactsContract.Contacts._ID));
    Cursor pCur = cr.query(
          ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
          null, 
          ContactsContract.CommonDataKinds.Email.CONTACT_ID +" = ?", 
          new String[]{id}, null);


    while (pCur.moveToNext())
    {
        String email = pCur.getString(
            pCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
        // your email handling code would go in here
    } 
    pCur.close();
  }
}