注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

分享,态度 ·~~

—— 十年太长,五年;如果可以回到五年前,你最想对那时候的自己说什么?

 
 
 

日志

 
 

联系人数据库contacts , data , raw_contacts表相关  

2011-01-18 09:45:40|  分类: Android |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

联系人data表

类 
android.provider.ContactsContract.Data
 
Constants for the data table, which contains data points tied to a raw contact. For example, a phone number or email address.

Data kinds
Data is a generic table that can hold all kinds of data. Sync adapters and applications can introduce their own data kinds. The kind of data stored in a particular row is determined by the mime type in the row. Fields from DATA1 through DATA15 are generic columns whose specific use is determined by the kind of data stored in the row. For example, if the data kind is Phone.CONTENT_ITEM_TYPE, then DATA1 stores the phone number, but if the data kind is Email.CONTENT_ITEM_TYPE, then DATA1 stores the email address.

ContactsContract defines a small number of common data kinds, e.g. ContactsContract.CommonDataKinds.Phone, ContactsContract.CommonDataKinds.Email etc. As a convenience, these classes define data kind specific aliases for DATA1 etc. For example, Phone.NUMBER is the same as Data.DATA1.

DATA1 is an indexed column and should be used for the data element that is expected to be most frequently used in query selections. For example, in the case of a row representing email addresses DATA1 should probably be used for the email address itself, while DATA2 etc can be used for auxiliary information like type of email address.

By convention, DATA15 is used for storing BLOBs (binary data).

Typically you should refrain from introducing new kinds of data for 3rd party account types. For example, if you add a data row for "favorite song" to a raw contact owned by a Google account, it will not get synced to the server, because the Google sync adapter does not know how to handle this data kind. Thus new data kinds are typically introduced along with new account types, i.e. new sync adapters.

查询操作

=============================BEGIN===========================
// 1 Finding all Data of a given type for a given contact
 Cursor c = getContentResolver().query(Data.CONTENT_URI,
          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
          Data.CONTACT_ID + "=?" + " AND "
                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
          new String[] {String.valueOf(contactId)}, null);

// 2 Finding all Data of a given type for a given raw contact

Cursor c = getContentResolver().query(Data.CONTENT_URI,
          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
          Data.RAW_CONTACT_ID + "=?" + " AND "
                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
          new String[] {String.valueOf(rawContactId)}, null);
==========================END================================

data表存储了大部分的联系人实际信息,他的每一个列的名字之所以这么难看(叫做data1~data15),是因为data表想要存储各种各样的联系人信息,同时不想让每个联系人的数据库列数太长。比如联系人信息里面,光名字就可以分为family name,mid name,nick name;光电话号码可以分为手机,家里,办公室,传真云云;光邮件可以分成这般这般这般那般,相当的纷繁复杂。如果每个信息都作为一个列出现在数据库,那就是硕大一个稀疏矩阵了。
所以data表这样的设计,更实用,也易于扩展;缺点是难看。
不过虽然难看,却不难查询,因为数据库查询的时候,根据data表的mimetype_id来检索需要的内容。
2.1里面,data表的mimetype支持这么十来种,这些不一定能在dump出来的数据库看到,因为一般用不到。。

==========================BEGIN=================================
    *  StructuredName.CONTENT_ITEM_TYPE   //    "vnd.android.cursor.item/name"

    * Phone.CONTENT_ITEM_TYPE    // "vnd.android.cursor.item/phone_v2"

    * Email.CONTENT_ITEM_TYPE   // "vnd.android.cursor.item/email_v2"
    * Photo.CONTENT_ITEM_TYPE  //    "vnd.android.cursor.item/photo"
    * Organization.CONTENT_ITEM_TYPE   // .....
    * Im.CONTENT_ITEM_TYPE
    * Nickname.CONTENT_ITEM_TYPE    //  "vnd.android.cursor.item/nickname"
    * Note.CONTENT_ITEM_TYPE
    * StructuredPostal.CONTENT_ITEM_TYPE
    * GroupMembership.CONTENT_ITEM_TYPE
    * Website.CONTENT_ITEM_TYPE
    * Event.CONTENT_ITEM_TYPE
    * Relation.CONTENT_ITEM_TYPE
============================END================================

对于这些不同类型的查询,有些可以用
ContactsContract.CommonDataKinds.*来完成,
比如Email

=======================BEGIN=====================================
Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
 Cursor c = getContentResolver().query(uri,
          new String[]{Email.DISPLAY_NAME, Email.DATA},
          null, null, null);
======================END======================================


RawContacts表

类: android.provider.ContactsContract.RawContacts

Class Overview

Constants for the raw contacts table, which contains the base contact information per sync source. Sync adapters and contact management apps are the primary consumers of this API.

查询

============================BEGIN=====================================
// 1, Finding all raw contacts in a Contact is easy:
Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
          new String[]{RawContacts._ID},
          RawContacts.CONTACT_ID + "=?",
          new String[]{String.valueOf(contactId)}, null);

//There are two ways to find raw contacts within a specific account,
// you can either put the account name and type in the selection or pass them as query parameters.
// The latter approach is preferable, especially when you can reuse the URI:

Uri rawContactUri = RawContacts.URI.buildUpon()
          .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
          .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType)
          .build();
 Cursor c1 = getContentResolver().query(rawContactUri,
          RawContacts.STARRED + "<>0", null, null, null);
 ...
 Cursor c2 = getContentResolver().query(rawContactUri,
          RawContacts.DELETED + "<>0", null, null, null);

// The best way to read a raw contact along with all the data associated with it is by using the ContactsContract.RawContacts.Entity directory.
// If the raw contact has data rows, the Entity cursor will contain a row for each data row.
// If the raw contact has no data rows, the cursor will still contain one row with the raw contact-level information.

 Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
 Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
 Cursor c = getContentResolver().query(entityUri,
          new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
          null, null, null);
 try {
     while (c.moveToNext()) {
         String sourceId = c.getString(0);
         if (!c.isNull(1)) {
             String mimeType = c.getString(2);
             String data = c.getString(3);
             ...
         }
     }
 } finally {
     c.close();
 }
=============================END=============================================

关于ContactsContract.RawContactsEntity ,
说明:  Constants for the raw contacts entities table, which can be though of as an outer join of the raw_contacts table with the data table. It is a strictly read-only table.

If a raw contact has data rows, the RawContactsEntity cursor will contain a one row for each data row. If the raw contact has no data rows, the cursor will still contain one row with the raw contact-level information and nulls for data columns.


Contacts表。
直接抄一些过来。。
long  _ID  read-only  Row ID. Consider using LOOKUP_KEY instead.
String LOOKUP_KEY read-only An opaque value that contains hints on how to find the contact if its row id changed as a result of a sync or aggregation.
String DISPLAY_NAME read-only The display name for the contact. During aggregation display name is computed from display names of constituent raw contacts using a heuristic: a longer name or a name with more diacritic marks or more upper case characters is chosen.
long PHOTO_ID read-only Reference to the row in the ContactsContract.Data table holding the photo. That row has the mime type CONTENT_ITEM_TYPE. The value of this field is computed automatically based on the IS_SUPER_PRIMARY field of the data rows of that mime type.
int IN_VISIBLE_GROUP read-only An indicator of whether this contact is supposed to be visible in the UI. "1" if the contact has at least one raw contact that belongs to a visible group; "0" otherwise.
int HAS_PHONE_NUMBER read-only An indicator of whether this contact has at least one phone number. "1" if there is at least one phone number, "0" otherwise.
int TIMES_CONTACTED read/write The number of times the contact has been contacted. See markAsContacted(ContentResolver, long). When raw contacts are aggregated, this field is computed automatically as the maximum number of times contacted among all constituent raw contacts. Setting this field automatically changes the corresponding field on all constituent raw contacts.
long LAST_TIME_CONTACTED read/write The timestamp of the last time the contact was contacted. See markAsContacted(ContentResolver, long). Setting this field also automatically increments TIMES_CONTACTED. When raw contacts are aggregated, this field is computed automatically as the latest time contacted of all constituent raw contacts. Setting this field automatically changes the corresponding field on all constituent raw contacts.
int STARRED read/write An indicator for favorite contacts: '1' if favorite, '0' otherwise. When raw contacts are aggregated, this field is automatically computed: if any constituent raw contacts are starred, then this field is set to '1'. Setting this field automatically changes the corresponding field on all constituent raw contacts.
String CUSTOM_RINGTONE read/write A custom ringtone associated with a contact. Typically this is the URI returned by an activity launched with the ACTION_RINGTONE_PICKER intent.
int SEND_TO_VOICEMAIL read/write An indicator of whether calls from this contact should be forwarded directly to voice mail ('1') or not ('0'). When raw contacts are aggregated, this field is automatically computed: if all constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set to '1'. Setting this field automatically changes the corresponding field on all constituent raw contacts.
int CONTACT_PRESENCE read-only Contact IM presence status. See ContactsContract.StatusUpdates for individual status definitions. Automatically computed as the highest presence of all constituent raw contacts. The provider may choose not to store this value in persistent storage. The expectation is that presence status will be updated on a regular basic.
String CONTACT_STATUS read-only Contact's latest status update. Automatically computed as the latest of all constituent raw contacts' status updates.
long CONTACT_STATUS_TIMESTAMP read-only The absolute time in milliseconds when the latest status was inserted/updated.
String CONTACT_STATUS_RES_PACKAGE read-only The package containing resources for this status: label and icon.
long CONTACT_STATUS_LABEL read-only The resource ID of the label describing the source of contact status, e.g. "Google Talk". This resource is scoped by the CONTACT_STATUS_RES_PACKAGE.
long CONTACT_STATUS_ICON read-only The resource ID of the icon for the source of contact status. This resource is scoped by the CONTACT_STATUS_RES_PACKAGE.

【from http://gnibre.javaeye.com/blog/703748

  评论这张
 
阅读(3940)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017