如何从Android手机的联系人列表中获取电子邮件?

时间:2012-04-02 12:13:23

标签: android

我正在尝试从Android手机的联系人列表中获取各种电子邮件地址,如工作,家庭.....等。 因为我使用下面的代码,但我发现结果每次只有零 请帮我。 感谢

Cursor email = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, null,
                Data.CONTACT_ID + " =" + id, null, null);
        while (email.moveToNext()) {
            emailAdd = email.getString(ContactsContract.CommonDataKinds.Email.TYPE_WORK);
            //ContactsContract.CommonDataKinds.Email.TYPE_HOME)
        }
        Log.v("anim", " emailAdd:    " + emailAdd);

并且我还需要获取组织,昵称,网站。

1 个答案:

答案 0 :(得分:0)

Cursor emailCur = cr.query( 
    ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
    null,
    ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
    new String[]{id}, null); 
while (emailCur.moveToNext()) { 
    // This would allow you get several email addresses
        // if the email addresses were stored in an array
    String email = emailCur.getString(
                  emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
    String emailType = emailCur.getString(
                  emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
} 
emailCur.close();