[android研究联系人之四]联系人StructuredPostal/StructuredName数据操作

简介:


技术:Android联系人技术分析


知识点:分析联系人中StructuredPostal和StructuredName数据


重点:数据类型


首先分析第一个字段:StructuredPostal

它代表联系人的地址信息,如图表示字段:



先看看它有的类型吧:



有四种数据类型。


看源码中定义的四种类型:

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

还有种定义类型:type=0时,是自定义类型。它没有单独在字段中定义。


按下来分析,StructuredPostal中重要的字段:

先从源码中看起:

 /**
             * The full, unstructured postal address. <i>This field must be
             * consistent with any structured data.</i>
             * <p>
             * Type: TEXT
             */
            public static final String FORMATTED_ADDRESS = DATA;

            /**
             * Can be street, avenue, road, etc. This element also includes the
             * house number and room/apartment/flat/floor number.
             * <p>
             * Type: TEXT
             */
            public static final String STREET = DATA4;

            /**
             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
             * usually but not always mutually exclusive with street.
             * <p>
             * Type: TEXT
             */
            public static final String POBOX = DATA5;

            /**
             * This is used to disambiguate a street address when a city
             * contains more than one street with the same name, or to specify a
             * small place whose mail is routed through a larger postal town. In
             * China it could be a county or a minor city.
             * <p>
             * Type: TEXT
             */
            public static final String NEIGHBORHOOD = DATA6;

            /**
             * Can be city, village, town, borough, etc. This is the postal town
             * and not necessarily the place of residence or place of business.
             * <p>
             * Type: TEXT
             */
            public static final String CITY = DATA7;

            /**
             * A state, province, county (in Ireland), Land (in Germany),
             * departement (in France), etc.
             * <p>
             * Type: TEXT
             */
            public static final String REGION = DATA8;

            /**
             * Postal code. Usually country-wide, but sometimes specific to the
             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
             * <p>
             * Type: TEXT
             */
            public static final String POSTCODE = DATA9;

            /**
             * The name or code of the country.
             * <p>
             * Type: TEXT
             */
            public static final String COUNTRY = DATA10;


类型:StructuredPostal.CONTENT_ITEM_TYPE

StructuredPostal.FORMATTED_ADDRESS:对应Data.data1

StructuredPostal.TYPE:对应Data.data2:表示类型

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

StructuredPostal.STREET:对应Data.data4:表示街道

StructuredPostal.POBOX:对应Data.data5:表示邮箱

StructuredPostal.NEIGHBORHOOD:对应Data.data6:表示镇(看英文解释)

StructuredPostal.CITY:对应Data.data7:表示城市

StructuredPostal.REGION:对应Data.data8:表示区域(省级)

StructuredPostal.POSTCODE:对应Data.data9:表示邮编

StructuredPostal.COUNTRY:对应Data.data10:表示国家


最后会分析存入数据库的值。


下面分析:StructuredName

StructuredName中主要保存的是联系人 姓名,其 称呼名和其 拼音名
姓名的表示有以下两种方式:
第一种:DISPLAY_NAME
第二种:GIVEN_NAME+FAMILY_NAME
注:第一种和第二种应该是 互斥的。有些手机支持第一种,有些则支持第二种。但必须支持其中的一种。
称呼名 ,是指对人的称呼。比如 Mr Hu。它只有一个表示形式:PREFIX+MIDDLE_NAME+SUFFIX
注:很多手机都不支持该项。
拼音名是指汉语拼音的形式,或片假名的形式,或平假名的形式等。
它只有一个表示形式:PHONETIC_GIVEN_NAME+PHONETIC_MIDDLE_NAME+PHONETIC_FAMILY_NAME
注:很多手机都不支持该项。

接下来看看模拟器中提供的姓名有多少吧:
先看图:


国外人的姓名字段可真多啊,所以,要操作手机中的姓名,还是要非常的小心。不同的手机可能会有不一样的。

接着看显示的名字,在模拟器中是什么?

用户名的显示,就是上面提到的多个字段组合起来的。

Android手机具体会使用哪种方式表示姓名,可能会一样。但我们还是要看看系统源码中提供了哪些重要的字段:

 /**
             * The name that should be used to display the contact.
             * <i>Unstructured component of the name should be consistent with
             * its structured representation.</i>
             * <p>
             * Type: TEXT
             */
            public static final String DISPLAY_NAME = DATA1;

            /**
             * The given name for the contact.
             * <P>Type: TEXT</P>
             */
            public static final String GIVEN_NAME = DATA2;

            /**
             * The family name for the contact.
             * <P>Type: TEXT</P>
             */
            public static final String FAMILY_NAME = DATA3;

            /**
             * The contact's honorific prefix, e.g. "Sir"
             * <P>Type: TEXT</P>
             */
            public static final String PREFIX = DATA4;

            /**
             * The contact's middle name
             * <P>Type: TEXT</P>
             */
            public static final String MIDDLE_NAME = DATA5;

            /**
             * The contact's honorific suffix, e.g. "Jr"
             */
            public static final String SUFFIX = DATA6;

            /**
             * The phonetic version of the given name for the contact.
             * <P>Type: TEXT</P>
             */
            public static final String PHONETIC_GIVEN_NAME = DATA7;

            /**
             * The phonetic version of the additional name for the contact.
             * <P>Type: TEXT</P>
             */
            public static final String PHONETIC_MIDDLE_NAME = DATA8;

            /**
             * The phonetic version of the family name for the contact.
             * <P>Type: TEXT</P>
             */
            public static final String PHONETIC_FAMILY_NAME = DATA9;

            /**
             * The style used for combining given/middle/family name into a full name.
             * See {@link ContactsContract.FullNameStyle}.
             *
             * @hide
             */
            public static final String FULL_NAME_STYLE = DATA10;

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


没想到它会有这么多字段吧。


接下来分析这些字段:

类型:StructuredName.CONTENT_ITEM_TYPE

StructuredName.DISPLAY_NAME:对应Data.data1:表示显示的名字
StructuredName.GIVEN_NAME:对应Data.data2:表示名
StructuredName.FAMILY_NAME:对应Data.data3:表示family名(在国外表示父母的姓)
StructuredName.PREFIX:对应Data.data4:表示姓名前的称呼,如Sir(先生/女士)
StructuredName.MIDDLE_NAME :对应Data.data5:表示姓名中间的字
StructuredName.SUFFIX :对应Data.data6:表示姓名敬语的后缀(不知道是什么)
后面的几个字段,都是语音相关设置的。


今天又折腾了挺晚了,晚上参加一个会议,和朋友喝了点酒,头晕晕的。但还是要坚持,把自己整理的东西,分享给大家。一起学习进步吧!!


后面还有一个数据库存入分析,快点来看看吧:
先看地址存入数据库的字段:




接下来看姓名字段数据:




如果对联系人操作,有问题的,可以结合源码和操作数据库的内容分析,就一定能很快的解决问题。
问题的难,就是思考时间太少。只能多用心,花时间研究。总能解决问题。
做技术,不能太及,需要一步步稳。用事实说话。


好了,今天就介绍到这里,如果对文章中有问题的地方,欢迎 一起交流。。只有交流,才能更好的进步。


加油吧,朋友们!!!



目录
相关文章
|
3月前
|
安全 API Android开发
Android网络和数据交互: 解释Retrofit库的作用。
Android网络和数据交互: 解释Retrofit库的作用。
39 0
|
4月前
|
XML 物联网 API
Android Ble蓝牙App(五)数据操作
Android Ble蓝牙App(五)数据操作
|
4月前
|
数据库 Android开发 开发者
Android Studio入门之内容共享ContentProvider讲解以及实现共享数据实战(附源码 超详细必看)
Android Studio入门之内容共享ContentProvider讲解以及实现共享数据实战(附源码 超详细必看)
41 0
|
4月前
|
XML Java Android开发
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
Android Studio开发之使用内容组件Content获取通讯信息讲解及实战(附源码 包括添加手机联系人和发短信)
91 0
|
11天前
|
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.
10 0
|
11天前
|
网络协议 安全 API
Android网络和数据交互: 什么是HTTP和HTTPS?在Android中如何进行网络请求?
HTTP和HTTPS是网络数据传输协议,HTTP基于TCP/IP,简单快速,HTTPS则是加密的HTTP,确保数据安全。在Android中,过去常用HttpURLConnection和HttpClient,但HttpClient自Android 6.0起被移除。现在推荐使用支持TLS、流式上传下载、超时配置等特性的HttpsURLConnection进行网络请求。
10 0
|
24天前
|
XML Java Android开发
Android每点击一次按钮就添加一条数据
Android每点击一次按钮就添加一条数据
24 1
|
1月前
|
定位技术 API 数据库
基于Android的在线移动电子导航系统的研究与实现(论文+源码)_kaic
基于Android的在线移动电子导航系统的研究与实现(论文+源码)_kaic
|
1月前
|
存储 Android开发 C++
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
【Android 从入门到出门】第五章:使用DataStore存储数据和测试
36 3
|
6月前
|
存储 安全 Java
Android DataStore:安全存储和轻松管理数据
Android DataStore:安全存储和轻松管理数据