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

安卓android的联系人的contacts, raw contacts, and data的区别的更多相关文章

  1. Android根据联系人姓名首字符顺序读取通讯录

      Android根据联系人姓名首字符顺序读取通讯录 版权声明:本文为Zhang Phil原创文章,欢迎转载!转载请注明出处:http://blog.csdn.net/zhangphil 本文给出了A ...

  2. android管理联系人操作

    ContentProvider扩展之管理系统联系人 我们都知道ContentProvider是用来共享数据的,然而android本身就提供了大量的ContentProvider,例如联系人信息,系统的 ...

  3. Android系统联系人全特效实现(下),字母表快速滚动

    在上一篇文章中,我和大家一起实现了类似于Android系统联系人的分组导航和挤压动画功能,不过既然文章名叫做<Android系统联系人全特效实现>,那么没有快速滚动功能显然是称不上&quo ...

  4. Android系统联系人全特效实现(上),分组导航和挤压动画

    记得在我刚接触Android的时候对系统联系人中的特效很感兴趣,它会根据手机中联系人姓氏的首字母进行分组,并在界面的最顶端始终显示一个当前的分组.如下图所示: 最让我感兴趣的是,当后一个分组和前一个分 ...

  5. 安卓Android面试题大全

    56个问题都是经常用到的,可以深入研究下,也是必须掌握的开发必备知识. 安卓Android面试题汇总 搜集了一些Android面试题目,供将要面试或者正在面试的朋友参考. 1, 谈谈你对Activit ...

  6. Win7的64位系统如何搭建安卓Android开发环境

    在搭建安卓Android开发环境,那么现在比较主流的Win7的64位操作系统如何搭建呢?其实很简单,不需要设置任何环境变量,只需要下载两个程序包(ADT和JDK),下载的时候注意选择相应的64位程序包 ...

  7. Python 开发安卓Android及IOS应用库Kivy安装尝试

    Python 开发安卓Android及IOS应用库Kivy安装尝试: 先来看看这货可以用来制作什么应用: Create a package for Windows Create a package f ...

  8. android开发如何获取res/raw和assets文件夹的路径

    ---恢复内容开始--- android开发如何获取res/raw和assets文件夹的路径,主要分为两种情况: 1.如果你只是拷贝动作,那么你只需要得到res/raw和assets文件输入流就可以, ...

  9. VS2015配置安卓Android和iOS开发环境

    http://www.cjjjs.cn/paper/gzsh/627201502818357.aspx [摘要] 本文按照步骤一步步的介绍要下载安装的东西,都提供了下载地址.最后将所有需要的程序都打包 ...

随机推荐

  1. Redis学习笔记——数据类型及操作

    数据操作 redis是key-value的数据,所以每个数据都是一个键值对 键的类型是字符串 值的类型分为五种: 字符串string 哈希hash 列表list 集合set 有序集合zset 数据操作 ...

  2. 翻译:Laravel-4-Generators 使用自己定义代码生成工具高速进行Laravel开发

    使用自己定义代码生成工具高速进行Laravel开发 这个Laravle包提供了一种代码生成器,使得你能够加速你的开发进程.这些生成器包含: generate:model – 模型生成器 generat ...

  3. Web app root system property already set to different value 错误原因及解决

    http://yzxqml.iteye.com/blog/1761540 ——————————————————————————————————————————————————————————————— ...

  4. JAVASCRIPT+DHTML实现表格拖动

    自已做的,本来想在网上找前辈们做的,可是总找不到这种例子,要么找出来的太复杂, 要么就没法用,索性自己写了一个.看看还可以用!贡献出来,估计和我一样的菜鸟用的着! <html> <s ...

  5. 数据库 Oracle数据库对象二

    视图 --视图是对表逻辑抽象 --视图的好处:简化查询 --视图是一种虚表 --视图建立在已有表的基础上,视图赖以建立的这些吧称为基表. --向视图提供数据内容的语句为select语句,可以将视图理解 ...

  6. imx6 uboot splash image

    跟踪uboot代码,了解imx6 splash image的生成过程. 涉及文件: ./cpu/arm_cortexa8/start.S ./board/freescale/mx6q_sabresd/ ...

  7. 关系运算符:instanceof

    关系运算符:instanceof a instanceof Animal;(这个式子的结果是一个布尔表达式) a为对象变量,Animal是类名. 上面语句是判定a是否可以贴Animal标签.如果可以贴 ...

  8. Mac OSX使用 XAMPP path 下的php

    修改-/.bash_profile文件或.zshrc文件 export XAMPP_HOME=/Applications/XAMPP export PATH=${XAMPP_HOME}/bin:${P ...

  9. hdu 1425:sort(排序,经典题。快排模板)

    sort Time Limit : 6000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

  10. HTTP报文-->MVC

    引用 学习Web开发不好好学习HTTP报文,将会“打拳不练功,到老一场空”,你花在犯迷糊上的时间比你沉下心来学习HTTP的时间肯定会多很多. HTTP请求报文解剖 HTTP请求报文由3部分组成(请求行 ...