android:如何选择联系人电话号码

时间:2012-06-10 00:32:01

标签: android contacts

我需要选择联系电话号码,我过去常常这样做......

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

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

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

2 个答案:

答案 0 :(得分:1)

您可以要求联系人选择器为每部手机显示一个联系人,因此多次联系多部手机会出现:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
startActivityForResult(intent, PICK_CONTACT);

答案 1 :(得分: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();
        }
    }

}