Select multiple contacts from phone book in android

后端 未结 2 1936
情话喂你
情话喂你 2020-12-25 14:28

I need to select contact numbers/emails from phone book in android.

I have seen selecting one contact and getting the result back in onActivityResult fr

2条回答
  •  难免孤独
    2020-12-25 15:19

    Looks like there's no such 'official' way. Your question is basically the same as this one How to select multiple contacts with Android SDK which has reference to custom implementation.

    If You check AOSP Contacts application, there's no such possibility neither in documentation. The only thing I've observed from the source of AOSP Contacts is the following mention (in com.android.contacts.activities.PeopleActivity):

    // TODO fix or remove multipicker code
    //                else if (resultCode == RESULT_CANCELED && mMode == MODE_PICK_MULTIPLE_PHONES) {
    

    From MMS app source code You can observe the following (in ComposeMessageActivity):

    private void launchMultiplePhonePicker() {
        Intent intent = new Intent(Intents.ACTION_GET_MULTIPLE_PHONES);
        intent.addCategory("android.intent.category.DEFAULT");
        intent.setType(Phone.CONTENT_TYPE);
        // We have to wait for the constructing complete.
        ContactList contacts = mRecipientsEditor.constructContactsFromInput(true);
        int urisCount = 0;
        Uri[] uris = new Uri[contacts.size()];
        urisCount = 0;
        for (Contact contact : contacts) {
            if (Contact.CONTACT_METHOD_TYPE_PHONE == contact.getContactMethodType()) {
                    uris[urisCount++] = contact.getPhoneUri();
            }
        }
        if (urisCount > 0) {
            intent.putExtra(Intents.EXTRA_PHONE_URIS, uris);
        }
        startActivityForResult(intent, REQUEST_CODE_PICK);
    }
    

    Field Intents.ACTION_GET_MULTIPLE_PHONES is available in ContactsContract.java but I wasn't able to find any usage of it across AOSP. So, I think it's some dead code or that action get handled in some closed code. I've tried the same way to launch contacts selection from my test application and got only exception about no application to handle the action.

    Of course, vendors Contacts applications provide such abilities (e.g. then selecting messages recipient), but it's better not to rely on them.

提交回复
热议问题