安卓android的联系人的contacts, raw contacts, and data的区别

https://stackoverflow.com/questions/5151885/android-new-data-record-is-added-to-the-wrong-contact/5158059#5158059

https://developer.android.com/guide/topics/providers/contacts-provider.html

https://stackoverflow.com/questions/35448250/how-to-get-whatsapp-contacts-from-android/35453979#35453979

https://developer.android.com/reference/android/provider/ContactsContract.RawContactsEntity.html

https://developer.android.com/reference/android/provider/ContactsContract.Data.html

 

 

 

Couple of Key pointers:

  • Contacts._ID = Data.CONTACT_ID
  • RawContacts._ID = Data.RAW_CONTACT_ID
  • RawContacts.CONTACT_ID = Contacts._ID
  • RawContactsEntity._ID = RawContacts._ID

Sounds confusing?? Let me try...

  1. The Contacts database is divided into 3 tables contactsraw contacts, and data.
  2. Each table contains column (_ID) which is an auto incremented primary key.
  3. data table contains all the contact info like phone number, mail id, address etc.
  4. The raw contacts points to the actual contact created. Hence we use the raw contacts while adding a contact.
  5. The user cannot add any data in the contacts table. The data in this table is populated internally due to aggregation of contacts.
  6. The reason your logic worked for some of the contacts is: _ID for contactsraw contactsremains same until there is any contact aggregation taking place. Lets say you add two contacts with same name abc. Here the _ID for raw contacts increments twice while _ID forcontacts increments only once as these two contacts gets merged due to the aggregation of contacts

Refer this for more details.

The best approach to fetch the info in your case is by using ContactsContract.RawContactsEntity ( an outer join of the raw_contacts table with the data table)

Reference:http://developer.android.com/reference/android/provider/ContactsContract.RawContactsEntity.html

 

 

here is the show Android Contact Data Store Diagram

转载于:https://www.cnblogs.com/welhzh/p/7168607.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值