0

I want to retrieve a cursor where in one row contains both name and phone number. Is the way to do this pretty, without any loops?

Uri uri = ContactsContract.Data.CONTENT_URI;
getContentResolver().query(uri,
                new String[] {ContactsContract.Data._ID, Phone.NUMBER,  StructuredName.GIVEN_NAME}, null, null, null)

1 Answers1

0

the code i use to get my contacts is:

Cursor cursor = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,null, null);

    String Contactos =" CONTACTOS DEL TELEFONO "+cursor.getCount()+"\n";

    while (cursor.moveToNext()) {
        String name =cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
        String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
        Contactos+="Nombre: "+name+"\n"+
                   "Telefono: "+phoneNumber+"\n"+
                   "----------------------------\n";
        }

then add the Contactos to a textview, and that's all! see ya!

Carlos Carrizales
  • 2,340
  • 3
  • 18
  • 24