是否可以从联系人Display_name +电话号码+电子邮件获得一个查询?

时间:2012-11-23 10:34:34

标签: android contacts

是否可以通过一个查询获取包含Display_namePhone NumberEmail的所有联系人列表?

1 个答案:

答案 0 :(得分: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);
}