April 8, 2014

How Whatsapp stores its contacts in android phones?

Whatsapp stores its contacts in the ContactsContract.Data table. For each Whatsapp contact it stores two entries in the same table. 

The common fields for both records for each contact are:
  • account_type = "com.whatsapp"
  • contact_id = 123 (Same _ID in ContactsContract.Contacts table)
Now the fields which have separate values are:
1. ContactsContract.Data.MIMETYPE
  • "vnd.android.cursor.item/vnd.com.whatsapp.profile" (if the record contains phone number).
  • "vnd.android.cursor.item/name" (if the record contains contact name).
2. ContactsContract.Data.DATA3
  • contains either the name or the phone number depending on the ContactsContract.Data.MIMETYPE
this can be understood with the help of following diagram:

how whatsapp stores ites contacts in phonebook
How Whatsapp stores its contacts in Android Phonebook?
Okay! Want to know how to read these contacts? Have a look at this post.

Feel free to post your comments, queries and suggestions. Thanks

2 comments:

  1. Very nice Post .. very well guided to
    also nice post about how to read whatsup Contact

    Can you kindly post code about how one can add his own icon & contact of person like whats up add into our contact list ,
    you guided well on how but can you post code for same how exactly one can achive it .
    Like if we using contact details to send sms , or call or to send email without intent ot without chooser as whats up does by directly writing into contact. can you post code for same about how to achieve this ..

    Thanking you..

    ReplyDelete
    Replies
    1. Thanks Sandeep for you feedback. To add your own contacts to the device you need the android.permission.WRITE_CONTACTS permission. here is an excellent example. Also don't forget to checkout the official docs.

      Delete