1 回答

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超9個(gè)贊
所有聯(lián)系人的所有信息都分組在別名表中,這些表實(shí)際上存儲(chǔ)在一個(gè)名為 的大表中,因此您可以簡單地查詢?cè)摫硪垣@取與Data特定聯(lián)系人相關(guān)的所有信息(您可以使用), 就像這樣: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();
}
添加回答
舉報(bào)