A contact selection call showing all contacts is made by the this link (as indicated here many times on SO):
Intent intent = new Intent( Intent.ACTION_PICK, Contacts.CONTENT_URI );
startActivityForResult( intent, REQ_CODE );
I get the name of the contact and all its phone numbers in onActivityResult with the following snippet:
public void onActivityResult( int requestCode, int resultCode, Intent intent )
{
Uri contactUri = intent.getData();
ContentResolver resolver = getContentResolver();
long contactId = -1;
Cursor cursor = resolver.query( contactUri,
new String[] { Contacts._ID, Contacts.DISPLAY_NAME },
null, null, null );
if( cursor.moveToFirst() )
{
contactId = cursor.getLong( 0 );
Log.i( "tag", "ContactID = " + Long.toString( contactId ) );
Log.i( "tag", "DisplayName = " + cursor.getString( 1 ) );
}
cursor = resolver.query( Phone.CONTENT_URI,
new String[] { Phone.TYPE, Phone.NUMBER },
Phone.CONTACT_ID + "=" + contactId, null, null );
while( cursor.moveToNext() )
{
Log.i( "tag", "PhoneNumber = T:" + Integer.toString( cursor.getInt( 0 ) ) + " / N:" + cursor.getString( 1 ) );
}
Calling a calling contact and only viewing contacts with a phone number can be done as follows (also found on SO):
Intent intent = new Intent( Intent.ACTION_PICK );
intent.setType( ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE );
startActivityForResult( intent, REQ_CODE );
If I do this, I see only those contacts in the contact picker that have at least one phone number, and this is exactly what I need. Unfortunately, with the code snippet above, I get only the display name, but NOT any phone numbers.
Does anyone have an idea what I need to change to get phone numbers?
Thanks in advance