Just do not pass ContactsContract.Contacts._ID
to query()
request :
phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null,
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
Update: Actually there are a few more problems in your code
There is no ContactsContract.Contacts.HAS_PHONE_NUMBER
column in ContactsContract.CommonDataKinds.Phone
table. You should just take ContactsContract.CommonDataKinds.Phone.NUMBER
and check if it's not empty.
Also you should use while (phones.moveToNext())
instead of while (phones.moveToFirst())
Please try this code:
phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null,
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
if (phones.getCount() > 0) {
while (phones.moveToNext()) {
String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
if (!TextUtils.isEmpty(phoneNumber)) {
String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String contactId = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
System.out.println("contactId="+ contactId+ ", name=" + name + ", phoneNumber=" + phoneNumber);
}
}