zoukankan      html  css  js  c++  java
  • android联系人app<二>

       首先接着上一篇,为什么谷歌设计联系人显示的时候姓名和电话不一起显示?

       这里我们先到谷歌官方看联系人的介绍:

         The Contacts Provider is an Android content provider component. It maintains three types of data about a person, each of which corresponds to a table offered by the provider, as illustrated in figurel.

        联系人数据是通过contentprovider来提供对外数据访问的。联系人内容提供者包含了联系人的三种类型数据,每一个 对应于内容提供者的一张表,关系如下图1所示:

    The three tables are commonly referred to by the names of their contract classes. The classes define constants for content URIs, column names, and column values used by the tables:

        上面三张表通常被contact类名所引用,下面的这些表使用了一些类,而这些类定义了uris常量,列名以及列对应的值。

    ContactsContract.Contacts table
    Rows representing different people, based on aggregations of raw contact rows.
    ContactsContract.RawContacts table
    Rows containing a summary of a person's data, specific to a user account and type.
    ContactsContract.Data table
    Rows containing the details for raw contact, such as email addresses or phone numbers.
    主要就是这三张表了。
     
    下面来看看contactprovider对外提供方问方式:  
    1  public static final String AUTHORITY = "com.android.contacts";
    2     /** A content:// style uri to the authority for the contacts provider */
    3     public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
    1 /**
    2          * The content:// style URI for this table, which requests a directory
    3          * of data rows matching the selection criteria.
    4          */
    5         public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");

    那么访问这些数据是通过封装好的query,delete update,insert等方法,而这些方法具有局限性,

     
    比如查询:
    1 Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
    2           new String[]{RawContacts._ID},
    3           RawContacts.CONTACT_ID + "=?",
    4           new String[]{String.valueOf(contactId)}, null);
    5  

    那么这里就有一个问题,就是一次只能查一张表,不能进行联合查询,因为使用resolver的默认方法中,它是将里面的内容填到sql语句对应的条件中,这种做法的好处是可以方便使用,其中封装对一些特殊字符的处理,但是问题是在相关的条件中没有联合查询如外连接 内连接这些,因此导致了在使用contentprovider访问系统数据就会有一次只能访问一个表的结果。

    那么系统提供一个范例,那就是可以先查询Raw.contact这个表,显示联系人的姓名,当点击这个联系人再根据联系人_id,通过data这个表获得联系人的其他信息。因此在很多厂商通讯录app在设计上就规避了这种风险,显示的时候,先显示姓名,通过多一步的操作来完成联系人详细信息的展示。

    那么假设如果产品经理要求你显示的时候就如同下面这样,该怎么办?

    做还是不做??

    要做的话 要怎么做?

     

      

      

  • 相关阅读:
    搭建Keil C51开发环境
    源码分析之Handler
    Android中的算法
    Android中的数据结构
    高级UI-UI绘制流程
    高级UI-Path和PathMeasure
    高级UI-画板Canvas
    高级UI-滤镜和颜色通道
    高级UI-高级渲染
    高级UI-画笔Paint
  • 原文地址:https://www.cnblogs.com/xilinch/p/2969656.html
Copyright © 2011-2022 走看看