I've gotten this snippet from StackOverflow:
Cursor people = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
try{
while (people.moveToNext()) {
int nameFieldColumnIndex = people
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
String contact = people.getString(nameFieldColumnIndex);
int numberFieldColumnIndex = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
String number = people.getString(numberFieldColumnIndex);
System.out.println(contact + "-" + number);
}
}catch(Exception e){
System.out.println(e);
}
people.close();
When I try to read phoneNum
column I get an error using String number = people.getString(numberFieldColumnIndex)
. Checking the column index I find that numberFiledColomnIndex = -1
.
How can I get this snippet working?