views:

507

answers:

1

I'm writing an application that requires the user to choose a contact from the contact list in order to send an SMS to that contact. Is there any way I can query the contact list for just those contacts with a phone number (i.e. not the ones with just e-mail addresses)? Currently my code looks like the following, but this shows all contacts - I then have to do the logic in my activity to inform the user if they've chosen a contact with no associated number and prompt them to choose another.

Intent i = new Intent(Intent.ACTION_PICK, People.CONTENT_URI);

A second thing, I realise the contact API changed from 2.0 onwards so what is the best practise for choosing contacts to cover all versions of the Android OS? Am I right in assuming the new contact API doesn't relate to pre 2.0?

A: 
Intent intent = new Intent(Intent.ACTION_PICK, Contacts.Phones.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT_RQCODE_OLD);

Shows the Phone Numbers aswell as the Contacts... :)

st0le
According to the docs, Contacts.Phones is deprecated and has been replaced by ContactsContract.* I think Contracts.Phones was the method used for pre 2.0.
jackbot
Which is fine if you want 1.6 compatibility...
Eno