技术: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
![](https://img-my.csdn.net/uploads/201212/02/1354459693_3609.png)
![](https://img-my.csdn.net/uploads/201212/02/1354459754_1094.png)
![](https://img-my.csdn.net/uploads/201212/02/1354459906_1579.png)
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:表示姓名敬语的后缀(不知道是什么)
后面的几个字段,都是语音相关设置的。
今天又折腾了挺晚了,晚上参加一个会议,和朋友喝了点酒,头晕晕的。但还是要坚持,把自己整理的东西,分享给大家。一起学习进步吧!!
后面还有一个数据库存入分析,快点来看看吧:
先看地址存入数据库的字段:
接下来看姓名字段数据:
如果对联系人操作,有问题的,可以结合源码和操作数据库的内容分析,就一定能很快的解决问题。
问题的难,就是思考时间太少。只能多用心,花时间研究。总能解决问题。
做技术,不能太及,需要一步步稳。用事实说话。
好了,今天就介绍到这里,如果对文章中有问题的地方,欢迎 一起交流。。只有交流,才能更好的进步。
加油吧,朋友们!!!