zoukankan      html  css  js  c++  java
  • RawContact

    public static final class
    ContactsContract.RawContacts
    extends Object
    implements BaseColumns ContactsContract.ContactOptionsColumns ContactsContract.RawContactsColumns ContactsContract.SyncColumns
    java.lang.Object
            android.provider.ContactsContract.RawContacts
    Class Overview
        Constants for the raw contacts table, 
        which contains one row of contact information for each person in each synced account. 

    raw contact就对应一个联系人
    Sync adapters and contact management apps are the primary consumers of this API. 
    Aggregation
        As soon as a raw contact is inserted or whenever its constituent data changes, 
        the provider will check if the raw contact matches other existing raw contacts and if so will aggregate it with those. 
        The aggregation is reflected in the ContactsContract.RawContacts table by the change of the CONTACT_ID field, 
        which is the reference to the aggregate contact.
        Changes to the structured name, organization, phone number, email address, or nickname trigger a re-aggregation. 
    参照Contact类的描述
        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和组(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)
        关于分组机制的编程可参考类ContactsContract.AggregationExceptions.
    一个raw contact的信息主要由主表(raw contact类声明的数据列),多项子表数据ContactsContract.Data来进行表示
    子表数据可以通过设置MIMETYPE项的值来表示多种类型的数据
    比如通过设置MIMETYPE项为StructuredName.CONTENT_ITEM_TYPE来说明是StructuredName数据。
    当然对于DATA1~DATA15也要按照StructuredName中定义的数据格式来写入数据。
    子表数据可以是
        *  StructuredName.CONTENT_ITEM_TYPE
        * Phone.CONTENT_ITEM_TYPE
        * Email.CONTENT_ITEM_TYPE
        * Photo.CONTENT_ITEM_TYPE
        * Organization.CONTENT_ITEM_TYPE
        * Im.CONTENT_ITEM_TYPE
        * Nickname.CONTENT_ITEM_TYPE
        * Note.CONTENT_ITEM_TYPE
        * StructuredPostal.CONTENT_ITEM_TYPE
        * GroupMembership.CONTENT_ITEM_TYPE
        * Website.CONTENT_ITEM_TYPE
        * Event.CONTENT_ITEM_TYPE
        * Relation.CONTENT_ITEM_TYPE

    :关于子表每种类型的具体数据格式都android.provider.ContactsContract.CommonDataKinds包中相关类找到说明。比如Email是在CommonDataKinds.Email中.
    主表数据共18项
    变量名                                列名                                备注
     _ID                                _id                                    这个就是raw_contact_id
     CONTACT_ID                        contact_id
     AGGREGATION_MODE                  aggregation_mode                        分组模式
     DELETED                               deleted                                是否已经被删除
     TIMES_CONTACTED                times_contacted
     LAST_TIME_CONTACTED            last_time_contacted
     STARRED                            starred
     CUSTOM_RINGTONE                    custom_ringtone   来电铃声的Url
     SEND_TO_VOICEMAIL                    send_to_voicemail
     ACCOUNT_NAME                        account_name
     ACCOUNT_TYPE                        account_type
     SOURCE_ID                            sourceid
     VERSION                            version
     DIRTY                                dirty
     SYNC1~SYNC1                        sync1~sync2
     注意1: _ID就是raw_contact_id
     注意2:当我们查询时,通常是查询没有删除的联系人。所以要加上条件RawContacts.DELETED==0:
     RawContacts.DELETED + "=?", new String[] {String.valueOf(0)}
     注意3:主表中没有名字的信息.名字在子表StructuredName中。
    子表数据共有25项
    变量名                            列名                                备注
     _ID                              _id       
     MIMETYPE                        mimetype
     RAW_CONTACT_ID                    raw_contact_id
     IS_PRIMARY                        is_primary
     IS_SUPER_PRIMARY                is_super_primary
     DATA_VERSION                    data_version
     DATA1~DATA15                    data1~data15
     SYNC1~SYNC4                    data_sync1~data_sync4一,数据插入可以参考《raw contact数据插入 》
    二,数据查询可以参考《rawContact数据查询 》
    三,数据更新
        final int        update(Uri  uri, ContentValues  values, String  where, String[]  selectionArgs)
        Update row(s) in a content URI.
        其使用很简单。
        ContentValues  values可以参考《rawContact数据插入 》
        String  where, String[]  selectionArgs可以参考《rawContact数据查询 》
        主表更新也可以用批量进行
        Raw contacts can be updated incrementally or in a batch.
        Batch mode should be used whenever possible. 
        The procedures and considerations are analogous to those documented above for inserts. 
        子表更新也可以用批量进行
        Just as with insert, update can be done incrementally or as a batch, the batch mode being the preferred method:
         ArrayList<ContentProviderOperation> ops = Lists.newArrayList();
         ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
                  .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
                  .withValue(Email.DATA, "somebody@android.com")
                  .build());
         getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);

    四,数据删除
        主表删除
            getContentResolver().delete(RawContacts.CONTENT_URI, null, null);
            注意:这里会除了会删除主表,也会把相应的子表删除掉。
        子表删除
            getContentResolver().delete(Data.CONTENT_URI, null, null)
        也可以批量删除
            Just as with insert and update, deletion can be done either using the delete(Uri, String, String[]) method 
            or using a ContentProviderOperation:
             ArrayList<ContentProviderOperation> ops = Lists.newArrayList();
             ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
                      .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
                      .build());
             getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
  • 相关阅读:
    【转】医院信息系统基本功能规范---门急诊划价收费分系统功能规范
    elementUI的table表头与内容错位的解决方案
    小程序按钮设置宽度无效的解决方案
    小程序scroll-view的bindscroll在真机上不触发的解决方案?
    小程序怎么设置input框和键盘的距离
    小程序动态获取元素高度报错VM14689:1 thirdScriptError Cannot read property 'height' of null;at SelectorQuery callback function TypeError: Cannot read property 'height' of null
    mpvue使用px与设计稿的转化
    SpringBoot中前后端数据交互
    Java并发-BlockingQueue
    Java并发-Fork/Join框架
  • 原文地址:https://www.cnblogs.com/carbs/p/2594705.html
Copyright © 2011-2022 走看看