Contact类 public static class Contacts implements BaseColumns, ContactsColumns,

ContactOptionsColumns, ContactNameColumns, ContactStatusColumns

对Contacts表共17项数据:
变量名                                            列名                                备注

 _ID                                                 _id

 LOOKUP_KEY                               lookup

                                                                     NAME_RAW_CONTACT_ID参照@1

 DISPLAY_NAME                             display_name                    在Contacts对列的描述为DISPLAY_NAME_PRIMARY

 PHOTO_ID                                     photo_id

 IN_VISIBLE_GROUP                       in_visible_group

 HAS_PHONE_NUMBER                   has_phone_number

 TIMES_CONTACTED                     times_contacted

 LAST_TIME_CONTACTED            last_time_contacted

 STARRED                                      starred

 CUSTOM_RINGTONE                    custom_ringtone

 SEND_TO_VOICEMAIL                    send_to_voicemail

 CONTACT_PRESENCE                    contact_presence

 CONTACT_STATUS                        contact_status

 CONTACT_STATUS_TIMESTAMP            contact_status_ts

 CONTACT_STATUS_RES_PACKAGE            contact_status_res_package

 CONTACT_STATUS_LABEL                contact_status_label

 CONTACT_STATUS_ICON                contact_status_icon

注意1:在Contacts对列的描述有NAME_RAW_CONTACT_ID,但没找到相应的变量和列名。

可能ContentResolver觉得把该项暴露给用户每什么意义,就把它隐藏起来了。该项应该是只给系统内部用的哦。

注意2:只有五项是可写TIMES_CONTACTED, LAST_TIME_CONTACTED, STARRED, CUSTOM_RINGTONE, SEND_TO_VOICEMAIL.

Operations

数据插入

    A Contact cannot be created explicitly. When a raw contact is inserted, the provider will first try to find a Contact representing the same person. 

    If one is found, the raw contact's CONTACT_ID column gets the _ID of the aggregate Contact. 

    If no match is found, the provider automatically inserts a new Contact 

    and puts its _ID into the CONTACT_ID column of the newly inserted raw contact.

    用户部能直接插入数据。数据的插入是由系统自动来完成的。

    

    当raw contact被插入或时,系统就会检查是否可以把该raw contact加到已经有的组(contact)。

    如果找到可以加入的组,就把组ID写到raw contact的CONTACT_ID这个数据项中。

    如果没找到就由系统重新创建一组,并把组ID写到raw contact的CONTACT_ID这个数据项中。

    如果raw contact的structured name, organization, phone number, email address, or nickname被改变。

    

    系统就会检查raw contact是否还属于raw contact的CONTACT_ID标记的那个组。

    如果发现raw contact不属于raw contact的CONTACT_ID标记的那个组。

    那么系统就会找是否可以把该raw contact加到已经有的其他组(contact)

    如果找到可以加入的组,就把组ID写到raw contact的CONTACT_ID这个数据项中。

    如果没找到就由系统重新创建一组,并把组ID写到raw contact的CONTACT_ID这个数据项中。

    注意:这的组是指contact(Aggregation of raw contact)

数据更新

    自动更新:当contact所包含的RawContacts的信息发生改变时,系统会对contact做相应的更新。

    手动强制更新:

    Only certain columns of Contact are modifiable: TIMES_CONTACTED, LAST_TIME_CONTACTED, STARRED, CUSTOM_RINGTONE, SEND_TO_VOICEMAIL. Changing any of these columns on the Contact also changes them on all constituent raw contacts.

    只有五项是可被用户直接更新。它们是TIMES_CONTACTED, LAST_TIME_CONTACTED, STARRED, CUSTOM_RINGTONE, SEND_TO_VOICEMAIL。

    当它们被手动强制更新时,contact所包含的RawContacts的相应项也会被一起更新。

数据删除

    Contacts文档说:

    Be careful with deleting Contacts! Deleting an aggregate contact deletes all constituent raw contacts.

    The corresponding sync adapters will notice the deletions of their respective raw contacts 

    and remove them from their back end storage.

    删除一个Contacts,会把它所包含所有raw contacts都删除掉。

    但是用下面语句居然删除不了任何Contacts.

    getContentResolver().delete(Contacts.CONTENT_URI, null, 

                    null);

    不过在删除Contacts的所有raw contacts后,Contacts也被删除了。

Query

        * If you need to read an individual contact, consider using CONTENT_LOOKUP_URI instead of CONTENT_URI.

        * If you need to look up a contact by the phone number, use PhoneLookup.CONTENT_FILTER_URI, which is optimized for this purpose.

        * If you need to look up a contact by partial name, e.g. to produce filter-as-you-type suggestions, use the CONTENT_FILTER_URI URI.

        * If you need to look up a contact by some data element like email address, nickname, etc, 

        use a query against the ContactsContract.Data table. The result will contain contact ID, name etc. 

可用如下语句进行查询:

        Cursor c=getContentResolver().query(Contacts.CONTENT_URI, null,

                null, null, Contacts.DISPLAY_NAME + " COLLATE NOCASE");

注意1:对于查单个contact信息时,可用CONTENT_LOOKUP_URI来进行查询

注意2:对于想通过电话号码查询时,可用PhoneLookup.CONTENT_FILTER_URI来查询。

具体参照《用PhoneLookup进行电话号码查询》

注意3:对于想通过名字的模糊查询来查询时,可以CONTENT_FILTER_URI URI来查询。

注意4: 对于想通过email address, nickname来查询时,可查询ContactsContract.Data表。

它的查询结果里面包含了contact ID, name等信息。具体可参考《raw contact子表数据查询》

注意5:可以使用CONTENT_STREQUENT_URI来查询starred和经常联系的联系人信息


关于Contact的Uri介绍.

CONTENT_LOOKUP_URI

public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI, "lookup");

A content:// style URI for this table that should be used to create shortcuts or otherwise create long-term links to contacts. 

This URI should always be followed by a "/" and the contact's LOOKUP_KEY. It can optionally also have a "/" and last known contact ID appended after that. This "complete" format is an important optimization and is highly recommended.

As long as the contact's row ID remains the same, this URI is equivalent to CONTENT_URI. 

If the contact's row ID changes as a result of a sync or aggregation, this URI will look up the contact using indirect information (sync IDs or constituent raw contacts).

Lookup key should be appended unencoded - it is stored in the encoded form, ready for use in a URI.

例如下:

    content://com.android.contacts/contacts/lookup/0n/400

注意:"On"是lookUpKey,"400"是Contacts._ID

得到CONTENT_LOOKUP_URI的方式有:

        1,从数据库中取得lookUpKey,然后再合成lookUpUri

        Cursor c=getContentResolver().query(Contacts.CONTENT_URI, null,

                null, null, Contacts.DISPLAY_NAME + " COLLATE NOCASE");

        Long contactId=cursor.getLong(cursor.getColumnIndex(Contacts._ID));

        //注意这里的lookUpKey是从Contacts表中取的

        String lookUpKey=cursor.getString(cursor.getColumnIndex(Contacts.LOOKUP_KEY));

        

        Uri lookUpUri=Contacts.getLookupUri(contactId, lookUpKey);     

        Cursor c = context.getContentResolver().query(lookUpUri, null,

                null, null, Contacts.DISPLAY_NAME + " COLLATE NOCASE");

        2,先用contactId合成contactUri,再用contactUri然后再合成lookUpUri.

        Uri contactUri=ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);

        Uri lookUpUri=Contacts.getLookupUri(context.getContentResolver(), contactUri);

另外可以从lookUpUri得到contactUri。

public static Uri lookupContact (ContentResolver resolver, Uri lookupUri)

Since: API Level 5

Computes a content URI (see CONTENT_URI) given a lookup URI.

Returns null if the contact cannot be found.

这里返回的是具体一个联系人的CONTENT_URI比如:content://com.android.contacts/contacts/400

CONTENT_URI

public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");

全部contacts

    全部contacts就是Contacts.CONTENT_URI(content://com.android.contacts/contacts)

某个人contacts

    具体某个人就是Contacts.CONTENT_URI/contactId的形式。

比如:

    content://com.android.contacts/contacts/400

某个人contacts可用如下方式合成

Uri contactUri=ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);

也可用它对具体一个人进行查询

Cursor c = context.getContentResolver().query(contentUri, null,

null, null, Contacts.DISPLAY_NAME + " COLLATE NOCASE");

CONTENT_FILTER_URI

public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI, "filter");

The content:// style URI used for "type-to-filter" functionality on the CONTENT_URI URI. 

The filter string will be used to match various parts of the contact name.

The filter argument should be passed as an additional path segment after this URI.

用于对名字进行模糊查询。

String name="robin";

Uri uri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(name));

c=context.getContentResolver().query(uri, null,null,null,null);

CONTENT_STREQUENT_URI

public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath(CONTENT_URI, "strequent");

The content:// style URI for this table joined with useful data from ContactsContract.Data, 

filtered to include only starred contacts and the most frequently contacted contacts. 

它也是用于对联系人进行查询,但是只返回starred和经常联系的联系人信息。

比如:

c=context.getContentResolver().query(Contacts.CONTENT_STREQUENT_URI, null,null,null,null);

返回的列和CONTENT_URI查询一样,也是17项数据。

CONTENT_STREQUENT_FILTER_URI

public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath(CONTENT_STREQUENT_URI, "filter");

The content:// style URI used for "type-to-filter" functionality on the CONTENT_STREQUENT_URI URI. 

The filter string will be used to match various parts of the contact name. 

The filter argument should be passed as an additional path segment after this URI.

它是用于通过名字来对联系人进行模糊查询,但是只返回starred和经常联系的联系人信息。

比如:

String name="robin";

 Uri uri = Uri.withAppendedPath(Contacts.CONTENT_STREQUENT_FILTER_URI, Uri.encode(name));

 c=context.getContentResolver().query(uri, null,null,null,null);

返回的列和CONTENT_URI查询一样,也是17项数据。

Contact类解析的更多相关文章

  1. Bootstrap 类解析

    Bootstrap 类解析 元素 Bootstrap 类 定义 <div> container 内容容器 <table> table 表格 <table> tabl ...

  2. 【Owin 学习系列】2. Owin Startup 类解析

    Owin Startup 类解析 每个 Owin 程序都有 startup 类,在这个 startup 类里面你可以指定应用程序管道模型中的组件.你可以通过不同的方式来连接你的 startup 类和运 ...

  3. Thrift compiler代码生成类解析

    代码生成类解析: Thrift--facebook RPC框架,介绍就不说了,百度,google一大把,使用也不介绍,直接上结构和分析吧. Hello.thrift文件内容如下: namespace ...

  4. SpringBoot入门(三)——入口类解析

    本文来自网易云社区 上一篇介绍了起步依赖,这篇我们先来看下SpringBoot项目是如何启动的. 入口类 再次观察工程的Maven配置文件,可以看到工程的默认打包方式是jar格式的. <pack ...

  5. Spark 资源调度包 stage 类解析

    spark 资源调度包 Stage(阶段) 类解析 Stage 概念 Spark 任务会根据 RDD 之间的依赖关系, 形成一个DAG有向无环图, DAG会被提交给DAGScheduler, DAGS ...

  6. 【Spring注解驱动开发】AOP核心类解析,这是最全的一篇了!!

    写在前面 昨天二狗子让我给他讲@EnableAspectJAutoProxy注解,讲到AnnotationAwareAspectJAutoProxyCreator类的源码时,二狗子消化不了了.这不,今 ...

  7. 【Python】-【类解析】--【脚本实例】

    通过脚本事例,解析下Python中类的几个概念在脚本中的应用 脚本如下: ++++++++++++++++++++++++++++++++++++++++ #!/usr/bin/env python# ...

  8. .net HTMLParser详细使用说明 强大的Filter类 解析HTML文档如此简单

    背景: HTMLParser原本是一个在sourceforge上的一个Java开源项目,使用这个Java类库可以用来线性地或嵌套地解析HTML文本.他的 功能强大和开源等特性吸引了大量Web信息提取的 ...

  9. Spring源码情操陶冶-AOP之Advice通知类解析与使用

    阅读本文请先稍微浏览下上篇文章Spring源码情操陶冶-AOP之ConfigBeanDefinitionParser解析器,本文则对aop模式的通知类作简单的分析 入口 根据前文讲解,我们知道通知类的 ...

随机推荐

  1. Asp.Net中GridView加入鼠标滑过的高亮效果和单击行颜色改变

    转载自:http://www.cnblogs.com/fly_dragon/archive/2010/09/03/1817252.html protected void GridView1_RowDa ...

  2. BZOJ 1877: [SDOI2009]晨跑( 最小费用最大流 )

    裸的费用流...拆点, 流量限制为1, 最后的流量和费用即答案. ------------------------------------------------------------------- ...

  3. 【CSDN博客之星评选】我为什么坚持写博客

    今天无意中在CSDN的博客之星评选活动看到自己竟然是候选人之一,真的是十分的惊讶也十分的高兴.对于喜欢写东西.喜欢分享的我来说,已经忍不住用文字来记录一下今天的美好心情,同时也让我回想起我是如何开始在 ...

  4. 网络授时服务 NTP

    NTP  --- Network Time Protocol 网络授时服务,他解决的主要问题就是实现两台或者多台机器的时间同步问题,而传统的格林尼治时间不是标准的时间,因为地球自转的不是规则的. 网络 ...

  5. SVN的trunk、branch、tag(二)

    转——简单的对比 SVN的工作机制在某种程度上就像一颗正在生长的树: 一颗有树干和许多分支的树 分支从树干生长出来,并且细的分支从相对较粗的树干中长出 一棵树可以只有树干没有分支(但是这种情况不会持续 ...

  6. JVM调优总结(四)-垃圾回收面临的问题

    如何区分垃圾 上面说到的“引用计数”法,通过统计控制生成对象和删除对象时的引用数来判断.垃圾回收程序收集计数为0的对象即可.但是这种方法无法解决循环引用.所以,后来实现的垃圾判断算法中,都是从程序运行 ...

  7. 双缓冲绘图和窗口控件的绘制——ATL ActiveX 窗口控件生成向导绘制代码OnDraw的一个错误 .

    双缓冲绘图和窗口控件的绘制 ---ATL ActiveX 窗口控件生成向导绘制代码OnDraw的一个错误 cheungmine 我们通常使用ATL COM组件,生成一个带窗口的ActiveX控件,然后 ...

  8. PredictionIO Open Source Machine Learning Server

    PredictionIO Open Source Machine Learning Server Build Smarter Software with Machine Learning Predic ...

  9. AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3參数含义

    arg0:是指父Vjew arg1就是你点击的那个Item的View arg2是position,position是你适配器里面的position arg3是id,通常是第几个项.id是哪个项View ...

  10. c语言,数组和字符串

    1. “数组名代表了数组的存储首地址,是一个地址常量”. 对于char *p1 = "A String."; 和 char p2[] = "Another String. ...