In Chapter 7, Databases and Content Providers (p.241) Listing 7-19, Accessing the contact Content Provider, the example given to extract the phone number does not work. Instead, this code extracts the contact name and the corresponding contact ID. I haven't been able to figure out how to display the phone number:
Obtain a cursor for every aggregated contact
Code:
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
// Let the Activity manage the cursor life cycle
startManagingCursor(people);
int nameIndex = people.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME);
int contactIndex = people.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone._ID);
if(people.moveToFirst()) {
do {
// Extract the phone number
String phone = people.getString(contactIndex);
String name = people.getString(nameIndex);
Toast.makeText(SampleProvider.this, name + ": " + phone, Toast.LENGTH_SHORT).show();
} while(people.moveToNext());
stopManagingCursor(people);