1

I am making a communication app that has been set up with a specific Account type in the AccountManager and has a SyncAdapter attached to it. Several of my contacts have a RawContact which has a MIMETYPE of my new account and some associated data.

I am looking for the correct way to query a list/cursor of every contact in a phones contact list that has one of these new accounts attached to it. I want to get the whole contact so i can do things like retrieve their phone numbers, display names and uris for pictures, but i only need the contacts that have my new type of account attached.

I have a feeling i need to join two tables together with some projection or selection parameters to get all of this data in one cursor object. Im just not sure how exactly to do this, though ive tried a bunch of different things already, namely being able to get all the contacts, or all the RawContact rows for my specific account type, but not both together.

Thanks

Glenn.nz
  • 2,261
  • 2
  • 17
  • 20

1 Answers1

3

Get Raw_Id's of all contacts matching the account type and name:

    getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI,
                                 new String[]{ContactsContract.RawContacts._ID,
                                 },
                                ContactsContract.RawContacts.ACCOUNT_NAME + " = ? AND " +
                                ContactsContract.RawContacts.ACCOUNT_TYPE + " = ? ",
                                new String[]{mAcccountName,mAccountType},null
                             );

For each _ID, fetch all rows from ContactsContract.Data , ContactsContract.RawContacts._ID matches ContactsContract.Data.RAW_CONTACT_ID here.

These rows have all the data related to that contact's Raw_id.

Refer to the documentation for the structure of ContactsContract.Data table, and what data it holds.

S.D.
  • 29,290
  • 3
  • 79
  • 130
  • please see my query...http://stackoverflow.com/questions/20215108/android-match-contact-from-contactlist/20217864?noredirect=1#comment30178455_20217864 – ADT Nov 27 '13 at 10:53