I used to use content resolver previously to fetch Contact list and their details while that still works I wanted to try the Loader method which queries the Content Provider
In my case the problem was with URI.
I was using this:
Uri uri = ContactsContract.Contacts.CONTENT_URI;
and I changed for this (Phone.CONTENT_URI) to resolve the problem and obtain the phone number:
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
This is the rest of the code:
contactos = (TextView) findViewById(R.id.contactos);
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String [] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
while (cursor.moveToNext()){
String nombre = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
String telefono = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contactos.append("Name: ");
contactos.append(nombre);
contactos.append(" - Phone Number: ");
contactos.append(telefono);
contactos.append("\n");
}