android联系人app<二>

简介: 首先接着上一篇,为什么谷歌设计联系人显示的时候姓名和电话不一起显示?    这里我们先到谷歌官方看联系人的介绍:      The Contacts Provider is an Android content provider component.

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

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

     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在设计上就规避了这种风险,显示的时候,先显示姓名,通过多一步的操作来完成联系人详细信息的展示。

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

做还是不做??

要做的话 要怎么做?

 

 

  

  

目录
相关文章
|
4月前
|
XML 物联网 API
Android Ble蓝牙App(五)数据操作
Android Ble蓝牙App(五)数据操作
|
3月前
|
Android开发 开发者 iOS开发
APP开发后如何上架,上架Android应用市场前要准备什么
移动应用程序(APP)的开发已经成为现代企业和开发者的常见实践。然而,开发一个成功的APP只是第一步,将其上架到应用商店让用户下载和使用是实现其潜力的关键一步。
|
4天前
|
测试技术 Android开发
Android App获取不到pkgInfo信息问题原因
Android App获取不到pkgInfo信息问题原因
14 0
|
1月前
|
设计模式 测试技术 数据库
基于Android的食堂点餐APP的设计与实现(论文+源码)_kaic
基于Android的食堂点餐APP的设计与实现(论文+源码)_kaic
|
2月前
|
安全 Java 数据挖掘
当 App 有了系统权限,真的可以为所欲为? Android Performance Systrace
当 App 有了系统权限,真的可以为所欲为? Android Performance Systrace 转载自: https://androidperformance.com/2023/05/14/bad-android-app-with-system-permissions/#/0-Dex-%E6%96%87%E4%BB%B6%E4%BF%A1%E6%81%AF
31 0
|
3月前
|
Android开发
闲暇时间收集和整理的Android的一些常用的App
闲暇时间收集和整理的Android的一些常用的App
14 0
|
3月前
|
Android开发 UED 开发者
解释Android App Bundle是什么,它的优势是什么?
解释Android App Bundle是什么,它的优势是什么?
58 0
|
3月前
|
JavaScript Android开发
Cordova 后台运行 Android APP
Cordova 后台运行 Android APP
|
4月前
|
物联网 Android开发
Android Ble蓝牙App(七)扫描过滤
Android Ble蓝牙App(七)扫描过滤