As stated in the title, I want to query all Contacts that have specified a phone number and return a cursor that contains only the display name and company name of the contact. I would like only 1 row returned for each contact.
Here is what I have come up with so far:
Cursor contactsCur = getContentResolver().query(
ContactsContract.Data.CONTENT_URI,
new String[] {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Organization.COMPANY},
ContactsContract.Contacts.HAS_PHONE_NUMBER + " >? AND " + Contacts.Data.MIMETYPE + " =? " ,
new String[] {"0", ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE},
null );
This will return 1 row for each Contact that has both a phone number and a company specified – it does not include contacts that have not specified a company.
I know why it does that – the AND " + Contacts.Data.MIMETYPE + " =? " bit of the query prevents any contact without a company from being returned. The problem is that without the AND part, multiple rows for each contact is returned.
It appears this is because ContactsContract.CommonDataKinds.Organization.COMPANY actually refers to ContactsContract.Contacts.Data.DATA1 , which is a general use field.
Any help on this will be greatly appreciated!
I ended up using multiple queries for this