[android研究联系人之三]联系人Phone/Organization数据操作

简介:


技术:Android联系人数据库分析


知识点:分析联系人中Phone和Organization数据。


重点:数据类型


联系人数据库中,最重要的当然是手机号字段。接下来仔细分析该字段了。

先看Android提供了多少种类型:下面是从模拟器中截的类型图:




看到这么多截图,就知道一个手机字段的类型有多少了吧。总共21种类型(实际真实的手机中,当然不会有这么全)。


来看系统源码中对类型的定义:

            public static final int TYPE_HOME = 1;
            public static final int TYPE_MOBILE = 2;
            public static final int TYPE_WORK = 3;
            public static final int TYPE_FAX_WORK = 4;
            public static final int TYPE_FAX_HOME = 5;
            public static final int TYPE_PAGER = 6;
            public static final int TYPE_OTHER = 7;
            public static final int TYPE_CALLBACK = 8;
            public static final int TYPE_CAR = 9;
            public static final int TYPE_COMPANY_MAIN = 10;
            public static final int TYPE_ISDN = 11;
            public static final int TYPE_MAIN = 12;
            public static final int TYPE_OTHER_FAX = 13;
            public static final int TYPE_RADIO = 14;
            public static final int TYPE_TELEX = 15;
            public static final int TYPE_TTY_TDD = 16;
            public static final int TYPE_WORK_MOBILE = 17;
            public static final int TYPE_WORK_PAGER = 18;
            public static final int TYPE_ASSISTANT = 19;
            public static final int TYPE_MMS = 20;

怎么只有20种类型,难道我数错了???

这怎么可能 ,当然不会少了,还有一个数据就是类型为0的自定义的数据。


接下来,分析Phone中,最重要的几个字段数据:

类型:ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE

Phone.NUMBER:对应Data.data1:表示手机数据,如:13810000000

Phone.TYPE:对应Data.data2:表示手机类型。注意:为0时,为自定义类型。

Phone.LABEL:对应Data.data3:表示自定义类型的名称(只有type为0时,才有此值)。


分析起来,还是比较简单。基本没有太在的难度。


接下来分析Organization字段:

先也看看系统提供了多少种类型:

看图:


类型只有这三种。


看看源码对类型的定义:

            public static final int TYPE_WORK = 1;
            public static final int TYPE_OTHER = 2;

又缺少了自定义类型。看来自定义类型是单独定义了。


接着看模拟器中的Organization数据操作:

看图:



难道中有这两个字段?

当然不是,不知模拟器中会这么简单。

还是看源码中,定义了哪些可操作的数据吧:

 /**
             * The company as the user entered it.
             * <P>Type: TEXT</P>
             */
            public static final String COMPANY = DATA;

            /**
             * The position title at this company as the user entered it.
             * <P>Type: TEXT</P>
             */
            public static final String TITLE = DATA4;

            /**
             * The department at this company as the user entered it.
             * <P>Type: TEXT</P>
             */
            public static final String DEPARTMENT = DATA5;

            /**
             * The job description at this company as the user entered it.
             * <P>Type: TEXT</P>
             */
            public static final String JOB_DESCRIPTION = DATA6;

            /**
             * The symbol of this company as the user entered it.
             * <P>Type: TEXT</P>
             */
            public static final String SYMBOL = DATA7;

            /**
             * The phonetic name of this company as the user entered it.
             * <P>Type: TEXT</P>
             */
            public static final String PHONETIC_NAME = DATA8;

            /**
             * The office location of this organization.
             * <P>Type: TEXT</P>
             */
            public static final String OFFICE_LOCATION = DATA9;

            /**
             * The alphabet used for capturing the phonetic name.
             * See {@link ContactsContract.PhoneticNameStyle}.
             * @hide
             */
            public static final String PHONETIC_NAME_STYLE = DATA10;

原来还有这么多数据可以操作。我们就来分析这些字段吧:

类型: ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE

Organization.COMPANY:对应Data.data1:表示:公司/组织

Organization.TYPE:对应Data.data2:表示类型,就是上面的三种类型

Organization.LABEL:对应Data.data3:表示自定义类型名称

Organization.TITLE:对应Data.data4:表示标题

Organization.DEPARTMENT:对应Data.data5:表示部门

Organization.OFFICE_LOCATION:对应Data.data9:表示办公位置

其它的data6、7、9、10:表示是什么呢?在不同的手机,代表可能会有差异的。


这些字段,也比较简单,后面来看看从模拟器中导入出的数据库吧:



这个时候,发现了什么?Phone字段的Data4有数据了,这是代表什么数据呢?

先看源码它代表什么:

 /**
             * The phone number's E164 representation. This value can be omitted in which
             * case the provider will try to automatically infer it.  (It'll be left null if the
             * provider fails to infer.)
             * If present, {@link #NUMBER} has to be set as well (it will be ignored otherwise).
             * <P>Type: TEXT</P>
             */
            public static final String NORMALIZED_NUMBER = DATA4;
这个是什么?看上面的注释:明白E164就知道了:

通过度娘查询到的解释:

一个E.164号码由以下几个部分组成,不同部分之间可以用“-”、“.”或空格等连接:
  ENUM+国家码(1~3位数字)-地区码(n位数字)-电话号码(15-n位数字)。
  例如:北京的一个电话号码写成标准的E.164格式应是:+86-10-62618501

不明白的看百科的解释:http://baike.baidu.com/view/827326.htm


说白了,只是一种标准。

再看一下存入的数据图:


data1:存入的是号码。但有些手机会有一些分隔符。但data4:是反过来的数据。


但要注意:两条同类型的数据,是没有字段作区分。

                  所以,操作更新的时候要注意了。。。


写到这里,基本完成。欢迎一起和大家学习交流!!!



等到最后分析完成,再上传源码。。。感谢大家的关注!!!





目录
相关文章
|
3月前
|
安全 API Android开发
Android网络和数据交互: 解释Retrofit库的作用。
Android网络和数据交互: 解释Retrofit库的作用。
38 0
|
4月前
|
XML 物联网 API
Android Ble蓝牙App(五)数据操作
Android Ble蓝牙App(五)数据操作
|
4月前
|
数据库 Android开发 开发者
Android Studio入门之内容共享ContentProvider讲解以及实现共享数据实战(附源码 超详细必看)
Android Studio入门之内容共享ContentProvider讲解以及实现共享数据实战(附源码 超详细必看)
36 0
|
4月前
|
XML Java Android开发
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
75 0
|
4天前
|
Android开发 开发者
Android网络和数据交互: 请解释Android中的AsyncTask的作用。
Android&#39;s AsyncTask simplifies asynchronous tasks for brief background work, bridging UI and worker threads. It involves execute() for starting tasks, doInBackground() for background execution, publishProgress() for progress updates, and onPostExecute() for returning results to the main thread.
5 0
|
4天前
|
网络协议 安全 API
Android网络和数据交互: 什么是HTTP和HTTPS?在Android中如何进行网络请求?
HTTP和HTTPS是网络数据传输协议,HTTP基于TCP/IP,简单快速,HTTPS则是加密的HTTP,确保数据安全。在Android中,过去常用HttpURLConnection和HttpClient,但HttpClient自Android 6.0起被移除。现在推荐使用支持TLS、流式上传下载、超时配置等特性的HttpsURLConnection进行网络请求。
5 0
|
17天前
|
XML Java Android开发
Android每点击一次按钮就添加一条数据
Android每点击一次按钮就添加一条数据
21 1
|
1月前
|
定位技术 API 数据库
基于Android的在线移动电子导航系统的研究与实现(论文+源码)_kaic
基于Android的在线移动电子导航系统的研究与实现(论文+源码)_kaic
|
1月前
|
存储 Android开发 C++
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
30 3
|
6月前
|
存储 安全 Java
Android DataStore:安全存储和轻松管理数据
Android DataStore:安全存储和轻松管理数据