-1

In an android project i had this intent to pick a phone number from my contact list

        btnContacts.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Open Contacts
            Intent intent= new Intent(Intent.ACTION_PICK,  ContactsContract.Contacts.CONTENT_URI);
            intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
            startActivityForResult(intent, PICK_CONTACT);
        }
    });

and this to get the result

    @Override
public void onActivityResult(int reqCode, int resultCode, Intent data) {
    super.onActivityResult(reqCode, resultCode, data);

    switch (reqCode) {
        case (PICK_CONTACT) :
            if (resultCode == Activity.RESULT_OK) {
                Uri contactUri = data.getData();
                String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME };
                Cursor cursor = getActivity().getContentResolver().query(contactUri, projection, null, null, null);
                if (cursor != null && cursor.moveToFirst()) {
                    insertedPhoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                    formatContact(insertedPhoneNumber, name);
                }
            }
            break;
    }
}

I would like to know if there is a way to do the same operation but if the contact dindt had phone number i would retrive the email instead.

Thought
  • 5,326
  • 7
  • 33
  • 69

1 Answers1

0

I would like to know if there is a way to do the same operation but if the contact dindt had phone number i would retrive the email instead.

No. You ask for phone numbers you get phone numbers. If you need additional logic or ifs, then you need to code it yourself.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141