我會建議使用您的自定義視圖的聯繫人 - 這不是很困難,你可以自定義它,但是你想要的。我親自實施了你需要的功能。
在這裏看到:
String PHONE_CONTACTS_ORDER_CLAUSE = ContactsContract.Contacts.DISPLAY_NAME
+ " ASC";
List<PhoneContact> contacts = new ArrayList<PhoneContact>(); // I have defined the bean PhoneContact
String[] projection = { ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME }; //Choose the columns you need
Cursor cursor = this.getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, projection, null/* the place for your where clause*/, null/* the place for your where args*/,
PHONE_CONTACTS_ORDER_CLAUSE);
startManagingCursor(cursor);
int contactIdIdx = cursor.getColumnIndex(ContactsContract.Contacts._ID);
int displayNameIdx = cursor
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
while (cursor.moveToNext()) {
PhoneContact contact = new PhoneContact(); // This is a class i defined, use the data the way you like.
contact.setContactId(cursor.getString(contactIdIdx));
contact.setDisplayName(cursor.getString(displayNameIdx));
contacts.add(contact);
}
編輯 對不起寫評論時得到了分散注意力的接觸式ID實際上是聯繫相關數據的不同內容提供商之間的粘合劑。這些都是幾個供應商可以使用,看看是否有任何關聯的電話或電子郵件與該聯繫人:
ContactsContract.CommonDataKinds.Phone.CONTENT_URI
ContactsContract.CommonDataKinds.Email.CONTENT_URI
這種方法的缺點是,它需要的'READ_CONTACTS'權限查詢聯繫人提供商。 – tad 2013-10-31 20:55:00
@tad:替代總是感激! – 2013-11-01 08:15:19
如果你想堅持全球意圖而不是添加權限,那麼沒有純粹的選擇。您只能使用Intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_TYPE)或Intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE)'一次過濾一個屬性。如果您不想添加'READ_CONTACTS',請重新設計此交互以通過電話或電子郵件進行選擇。 – tad 2013-11-01 18:34:56