0

是否可以通过一个查询获取所有包含Display_name,Phone Number的联系人列表?Email

4

1 回答 1

0

查询相应的内容提供者 Uri。例如,android.provider.ContactsContract.CommonDataKinds.Email 允许您获取电子邮件地址,并且您的其他列(例如,IN_VISIBLE_GROUP)被隐式加入。

ContentResolver resolver = getContentResolver();
Cursor c = resolver.query(
        Data.CONTENT_URI, 
        null, 
        Data.HAS_PHONE_NUMBER + "!=0 AND (" + Data.MIMETYPE + "=? OR " + Data.MIMETYPE + "=?)", 
        new String[]{Email.CONTENT_ITEM_TYPE, Phone.CONTENT_ITEM_TYPE},
        Data.CONTACT_ID);

while (c.moveToNext()) {
    long id = c.getLong(c.getColumnIndex(Data.CONTACT_ID));
    String name = c.getString(c.getColumnIndex(Data.DISPLAY_NAME));
    String data1 = c.getString(c.getColumnIndex(Data.DATA1));

    System.out.println(id + ", name=" + name + ", data1=" + data1);
}
于 2012-11-23T10:48:37.120 回答