Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android contact picking - only contacts with numbers?

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?

like image 776
jackbot Avatar asked Oct 14 '22 03:10

jackbot


1 Answers

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... :)

like image 52
st0le Avatar answered Oct 18 '22 22:10

st0le