Reputation: 19484
Is there an efficient query to find all aggregate contacts for a specific account name & type?
The ContactsContract.Contacts
table has the IN_VISIBLE_GROUP
column which is effective for contact group membership. So, if the user has selected various group memberships for accounts, this column will be set.
There does not appear to be any equivalent in-visible-account column. However, the Android contacts app allows selecting a specific account to view without tapping "customize" and selecting groups. Doing this updates the ContactsContract.Settings
table. The effect does not appear to reach the Contacts
table.
I would like to be able to do one query and get one cursor back that has exactly the right set of aggregate (meaning from the Contacts table) contacts. Is this possible?
Upvotes: 1
Views: 573
Reputation: 28179
find all aggregate contacts for a specific account name & type
Contacts
are account specific, they're combined of multiple RawContacts
, each can be saved on a different Account
.
You can query for all the RawContacts
for a specific Account
:
Cursor c = cr.query(RawContacts.CONTENT_URI,
new String[]{ RawContacts._ID, RawContacts.CONTACT_ID, RawContacts._ID, ... },
RawContacts.ACCOUNT_NAME + " = '" + accountName + "' AND " + RawContacts.ACCOUNT_TYPE + " = '" + accountType + "'", null, null);
If you want Contacts
you can put all contact-ids you found in the above query in an array, and query on Contacts
table:
Cursor c = cr.query(Contacts.CONTENT_URI,
new String[]{ Contacts._ID, Contacts.DISPLAY_NAME, ... },
Contacts._ID + " IN (" + arrayOfIds + ")", null, null);
Upvotes: 2