Search code examples
androidapicontactscontactscontractrawcontacts

difference between RawContacts.CONTENT_URI and ContactsContract.Contacts.CONTENT_URI in android


what is the difference between RawContacts.CONTENT_URI and ContactsContract.Contacts.CONTENT_URI in android?

I am trying to write a service which listens to changes in native address book. So, which one to use?

thanks Niz


Solution

  • A Contact (as the user perceives it) is an aggregate set of RawContact's

    A RawContact being some details associated with a certain account or protocol

    The ContactsContract.Contacts.CONTENT_URI is generally the correct one to use as it brings back the correct display name from the entire set of matching RawContacts and can help you join all those accounts that are linked

    The RawContacts.CONTENT_URI can be used if you want to match a specific [set of] contact relating to an account/protocol

    and then there are various data types / directories to bring back even broader ranges of data.

    The question of which one should you use comes down to what data you are watching and if/how you are displaying it, as well as how many rows you are trying to watch. I would say more often than not it's correct to use the ContactsContract.

    It also depends how granular you want your 'notifications'. I.e. a content observer callback can give you a URL to show you what changed, but nothing more, which means if you want to only act on the specific row that you know has changed then you're going to have to observe different things than if you just want to know some change has occurred and that it's time to notifyDataSetChanged!