2

我需要选择联系电话号码,我曾经这样做......

Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(意图,GET_CONTACT_FROM_RESULT);

但是,当一个联系人有多个号码时,pick 活动只列出一个联系人,并且只能选择一个电话。

如何显示联系人的每个电话号码?

4

2 回答 2

1

您可以要求联系人选择器在每部电话中显示一个联系人,因此与多部电话的联系人会出现多次:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, PICK_CONTACT);
于 2012-06-20T11:44:15.837 回答
0
 public Map<String, String> lookupPhoneNoAndContactId(){
    Map<String, String> phonenumbers = new HashMap<String, String>();
    Cursor cursor = null;
    try {
        cursor = contentResolver.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                null, null, null);
        while (cursor.moveToNext()) {
            phonenumbers
                    .put(cursor
                            .getString(cursor
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)),
                            cursor.getString(cursor
                                    .getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID)));
        }
        return phonenumbers;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

}
于 2012-06-20T11:55:38.717 回答