Android如何获取一个联系人用户的多个电子邮件地址?

时间:2013-12-18 06:36:30

标签: android android-contacts

假设在Android中,手机联系人有多个电子邮件地址。 我需要获取与特定联系人列表相对应的电子邮件列表。 我怎么能这样做?

3 个答案:

答案 0 :(得分:2)

使用以下代码:

     Cursor emailCur = getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null
                          ,ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?"
                         , new String[]{id},null); 
     while (emailCur.moveToNext()) { 
                String email = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
                Log.e("Email",name+" "+email);
              } 
              emailCur.close();
          }

答案 1 :(得分:1)

ArrayList emailList = new ArrayList<String>();

Cursor Cur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                            ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
                            new String[]{id}, null); 
while (Cur.moveToNext()) { 
        String email = Cur.getString(Cur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));                            
        emailList.add(email);
    }

答案 2 :(得分:0)

以上所有答案都是正确的...但更多的澄清......它是:)

String homeEmail = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE_HOME));

String mobileEmail = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE_MOBILE));

String workEmail = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE_WORK));

String otherEmail = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE_OTHER));

String customEmail = emailCur.getString( emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE_CUSTOM));