1 回答
TA贡献1829条经验 获得超9个赞
所有联系人的所有信息都分组在别名表中,这些表实际上存储在一个名为 的大表中,因此您可以简单地查询该表以获取与Data特定联系人相关的所有信息(您可以使用), 就像这样:CONTACT_IDLOOKUP_URI
public void getContactInfo(long contactId) {
Uri uri = Data.CONTENT_URI;
String[] projection = new String[]{
Data.CONTACT_ID,
Data.DISPLAY_NAME,
Data.MIMETYPE,
Data.DATA1}; // you can get additional info if needed in Data.DATA2, DATA3, etc.
// get all relevant info about the contact
String selection = Data.CONTACT_ID + "=? AND " + Data.MIMETYPE + " IN (?,?,?,?)"; // you can add more question marks if you need more MIMETYPES
String[] selectionArgs = new String[]{String.valueOf(contactId), Phone.CONTENT_ITEM_TYPE, Email.CONTENT_ITEM_TYPE, Event.CONTENT_ITEM_TYPE, StructuredPostal.CONTENT_ITEM_TYPE};
Cursor cursor = getContentResolver().query(uri, projection, selection, selectionArgs, null);
while (cursor.moveToNext()) {
String name = cursor.getString(1);
String mimetype = cursor.getString(2);
String data = cursor.getString(3);
// use the mimetype to figure out what kind of info is in this row
Log.i("Contact Info", contactId + "=> " + name + " - " + mimetype + ": " + data);
}
cursor.close();
}
添加回答
举报