2

I want to call phones book to let user to pick one (or multiple optionally) phone numbers (I need only phone numbers and not the whole contacts info because I want to let the user to skip writing the number himself and pick one instead). This is what I found so far:

Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,  
                    ContactsContract.Contacts.CONTENT_URI);  
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);

This returns me a contact selected but then it might have no or many phone numbers (and I don't need them all. I need just one. I could let the user to choose it using ListView or Spinner but I believe there must be some API for that because Messages app on my phone has such picker (well, could be more comfortable but I assume it's an API and not the Messages app).

Pijusn
  • 11,025
  • 7
  • 57
  • 76
  • Have you seen http://stackoverflow.com/questions/3044545/get-contact-info-from-android-contact-picker ? – Jack Aug 11 '11 at 18:41
  • Well, that's exactly what I am talking about as a bad example... I want the user to pick the number and getting a bunch of numbers for the same contact is not what I need. I want the user to pick that EXACT number. Yes, I could do that without API but I hope there is something for that. – Pijusn Aug 11 '11 at 18:50
  • I didn't find way to create phone picker with api. I use contact picker and when user select contact application shows own dialog with all phones if they more then one, then user select phone to use. It's not good to use two clicks to select phone, but it's better than nothing... – garmax1 Sep 22 '12 at 09:05

1 Answers1

0

This is possible using the APIs, see: https://developer.android.com/guide/components/intents-common.html#Contacts

To have the user select a specific piece of information from a contact, such as a phone number, email address, or other data type, use the ACTION_PICK action and specify the MIME type to one of the content types listed below, such as CommonDataKinds.Phone.CONTENT_TYPE to get the contact's phone number.

A snippet of their example intent:

    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(CommonDataKinds.Phone.CONTENT_TYPE);
    startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER);

You can see how they handle the result in the docs linked above.

marmor
  • 27,641
  • 11
  • 107
  • 150