android - 联系人与原始联系人有什么区别?

标签 android contacts contactscontract rawcontacts

我有一个用于研究 ContactsContract 的“转储”实用程序,因为我在文档中并没有完全了解它。但是,当我转储联系人时,它会在表中记录 263 条记录,但我设备上的联系人应用程序列出了我有 244 条记录(“显示 244 条联系人。”)

谁能解释这个差异?

我的 Sprint LG 的联系人应用程序为我同步的每个帐户都有显示选项,我已经进入并检查了所有这些帐户,因此不应该有任何过滤。

我在实用程序中使用的主要 URI 是:

    Uri uriRawContacts = ContactsContract.RawContacts.CONTENT_URI;
    String[] projection = new String [] {
            ContactsContract.RawContactsEntity._ID,
            ContactsContract.RawContactsEntity.CONTACT_ID,
            ContactsContract.RawContactsEntity.DELETED,
            ContactsContract.RawContactsEntity.AGGREGATION_MODE,
    };
    Cursor cursorRaw = cr.query(uriRawContacts, projection, null, null, null);
    DumpCursor.dumpAnyCursor(getApplicationContext(), "RawContacts", cr, cursorRaw, ",");

后跟(对于上述查询中的每个_ID):

                long rawContactId = Long.parseLong(anyCursor.getString(anyCursor.getColumnIndex(RawContacts.CONTACT_ID)));

                Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
                 Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);

                 Log.d(TAG, "rawContactUri: " + rawContactUri.toString());
                 Log.d(TAG, "entityUri: " + entityUri.toString());

                 Cursor c = cr.query(entityUri, new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null, null);

然后我循环第一个查询,显示我的投影中的所有列,然后,使用第一个查询循环中的 _ID 字段,我发出第二个查询并转储它的所有列。

为方便起见,此处转置了答案中的项目符号: 请参阅引用资料以获得更详细的说明。更具体地说,我们鼓励您阅读聚合规则。 引用:Click here for the original cited text that follows

  • The Contacts database is divided into 3 tables contacts, raw contacts, and data.
  • Each table contains column (_ID) which is an auto incremented primary
    key.
  • The data table contains all the contact info like phone number, mail id,
    address etc.
  • The raw contacts points to the actual contact created. Hence we use the raw contacts while adding a contact.
  • The user cannot add any data in the contacts table. The data in this
    table is populated internally due to
    aggregation of contacts.

The reason your logic worked for some of the contacts is: _ID for contacts, raw contacts remains 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 for contacts increments only once as these two contacts gets merged due to the aggregation of contacts

最佳答案

这种差异是由于 RawContacts 由于聚合规则而合并到 Contacts 造成的。

当列表显示联系人时,您将联系人添加到 RawContacts。因此计数差异。

请在 ContactsRawContactsData 之间找到一些描述 here . 即使问题是不同的问题,您也可以了解 ContactsRawContacts 之间的区别。

关于android - 联系人与原始联系人有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5269079/

相关文章:

java - 当x和y位置进入另一个位置时如何执行操作?

android - 如何从已知联系人获取群组名称

android - 更新/设置自己的用户个人资料图像

android - 手动更新联系人的 ContentObserver

android - 在 Android 中从 URI 检索联系电话号码

android - 多次更改相对布局的高度

android - 实时无线传感器数据传输。 WiFi 还是蓝牙? TCP 还是 UDP?

java - Activity.class - 类文件编辑器 : The JAR file c:\sdk\platforms\android-17\android. jar 没有源附件

android - .android 文件夹中没有 debug.keystore

python - Google App Engine 样板 - 联系人模板