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. 原生sqlServer数据库连接

    package tj.test.demo; import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Sta ...

  2. [Java] 高效快速导入EXCEL数据

    需求1.高效率的以excel表格的方式导入多条数据.2.以身份证号为唯一标识,如果身份证号已存在,则该条数据不导入. 分析刚开始的时候是传统的做法,解析excel数据,获取单个对象,判断身份证是否已存 ...

  3. qt 使用多个ui文件

    一般的QT工程只有一个ui,本文记录如何在一个工程中使用多个ui文件. 参考链接: http://www.cnblogs.com/lc-cnblong/p/3182903.html 创建方法,鼠标在工 ...

  4. Web前端开发中的MCRV模式(转)

    作者: izujian  来源: baiduux 摘要:针对前端开发中基于ajax的复杂页面开发所面临的代码规模大,难以组织和维护,代码复用性.扩展性和适应性差等问题,本文尝试以MVC思想为 基础,结 ...

  5. js中的问题(this)(遍历对象中的属性)

    for (var i in this) { if (this[i] == null) this[i] = "";//属性如果为null,则默认为"";      ...

  6. git chekout分支遇到问题:need merge

    解决步骤: 在master上, 1.git add . 2.git commit 3.新建分支,并且checkout到此分支,重新提交

  7. hrbustoj 1306:再遇攻击(计算几何,判断点是否在多边形内,水题)

    再遇攻击 Time Limit: 1000 MS    Memory Limit: 65536 K Total Submit: 253(37 users)   Total Accepted: 56(2 ...

  8. WPF 在TextBox失去焦点时检测数据,出错重新获得焦点解决办法

    WPF 在TextBox失去焦点时检测数据,出错重新获得焦点解决办法 在WPF的TextBox的LostFocus事件中直接使用Focus()方法会出现死循环的问题 正确的使用方式有2中方法: 方法一 ...

  9. Python 使用正则表达式匹配IP信息

    使用正则表达式匹配IP地址 .MAC地址 .网卡名称: #!/usr/bin/env python #-*- coding:utf-8 -*- import re from subprocess im ...

  10. Java多线程实现自然同步(内含演示案例)

    1.准备一个生产者类: public class Producer extends Thread{ private String name; private Market mkt; static in ...