是否可以通过一个查询获取包含Display_name
,Phone Number
和Email
的所有联系人列表?
答案 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);
}