1.加入读写权限
联系人信息Uri:
content://com.android.contacts/contacts
联系人电话Uri:
content://com.android.contacts/data/phones
联系人Email Uri:
content://com.android.contacts/data/emails
(推荐)也可以这样获取联系人信息Uri:Uri uri = ContactsContract.Contacts.CONTENT_URI;
2.查询与添加联系人的操作(单元测试用例)
*******************************************************************************************************
这里主要使用的是
从Android 2.0 SDK开始有关联系人provider的类变成了ContactsContract,虽然老的android.provider.Contacts能用,但是在SDK中标记为为deprecated将被放弃不推荐的方法,而从Android 2.0及API Level为5开始新增了android.provider.ContactsContract来代替原来的方法。不过Android123表示大家做两手准备,毕竟目前70%的设备以及Ophone 1.0和1.5均不支持ContactsContract。
2011-01-15 23:52:01| 分类: Android |字号 订阅
1. ContactsContract.Contacts.TIMES_CONTACTED ="times_contacted"
The number of times a contact has been contacted
2. ContactsContract.Contacts.CONTACT_STATUS ="contact_status"
Contact's latest status update.
3. ContactsContract.Contacts.CUSTOM_RINGTONE ="custom_ringtone"
URI for a custom ringtone associated with the contact. Ifnull or missing, the default ringtone is used.
4. ContactsContract.Contacts.HAS_PHONE_NUMBER ="has_phone_number"
An indicator of whether this contact has at least one phonenumber. "1" if there is at least one phone number, "0"otherwise.
5. ContactsContract.Contacts.PHONETIC_NAME = "phonetic_name"
Pronunciation of the full name in the phonetic alphabetspecified by PHONETIC_NAME_STYLE.
6. ContactsContract.Contacts.PHONETIC_NAME_STYLE ="phonetic_name_style"
The phonetic alphabet used to represent the PHONETIC_NAME.See PhoneticNameStyle.
7. ContactsContract.Contacts.CONTACT_STATUS_LABEL ="contact_status_label"
The resource ID of the label describing the source ofcontact status, e.g. "Google Talk". This resource is scoped by theCONTACT_STATUS_RES_PACKAGE.
8. ContactsContract.Contacts.LOOKUP_KEY = "lookup"
An opaque value that contains hints on how to find thecontact if its row id changed as a result of a sync or aggregation.
9. ContactsContract.Contacts.CONTACT_STATUS_ICON ="contact_status_icon"
The resource ID of the icon for the source of contactstatus. This resource is scoped by the
CONTACT_STATUS_RES_PACKAGE.
10. ContactsContract.Contacts.LAST_TIME_CONTACTED= "last_time_contacted"
The last time a contact was contacted.
11. ContactsContract.Contacts.DISPLAY_NAME= "display_name"
The display name for the contact.
12. ContactsContract.Contacts.SORT_KEY_ALTERNATIVE= "sort_key_alt"
Sort key based on the alternative representation of thefull name, DISPLAY_NAME_ALTERNATIVE. Thus for Western names, it is the oneusing the "family name first" format.
13. ContactsContract.Contacts.IN_VISIBLE_GROUP= "in_visible_group"
Lookup value that reflects the GROUP_VISIBLE state of anyContactsContract.CommonDataKinds.GroupMembership for this contact.
14. ContactsContract.Contacts._ID= "_id"
The unique ID for a row.
15. ContactsContract.Contacts.STARRED= "starred"
Is the contact starred?
16. ContactsContract.Contacts.SORT_KEY_PRIMARY= "sort_key"
Sort key that takes into account locale-based traditionsfor sorting names in address books.
17. ContactsContract.Contacts.DISPLAY_NAME_ALTERNATIVE= "display_name_alt"
An alternative representation of the display name, such as"family name first" instead of "given name first" forWestern names. If an alternative is not available, the values should be thesame as DISPLAY_NAME_PRIMARY
18. ContactsContract.Contacts.CONTACT_PRESENCE= "contact_presence"
Contact presence status. See ContactsContract.StatusUpdatesfor individual status definitions.
19. ContactsContract.Contacts.DISPLAY_NAME_SOURCE= "display_name_source"
The kind of data that is used as the display name for thecontact, such as structured name or email address. See DisplayNameSources.TODO: convert DisplayNameSources to a link after it is un-hidden
20. ContactsContract.Contacts.CONTACT_STATUS_RES_PACKAGE= "contact_status_res_package"
The package containing resources for this status: label andicon.
21. ContactsContract.Contacts.CONTACT_STATUS_TIMESTAMP= "contact_status_ts"
The absolute time in milliseconds when the latest statuswas inserted/updated.
22. ContactsContract.Contacts.PHOTO_ID= "photo_id"
Reference to the row in the data table holding the photo.
23. ContactsContract.Contacts.SEND_TO_VOICEMAIL= "send_to_voicemail"
Whether the contact should always be sent to voicemail. Ifmissing, defaults to false.
可以用以下方法,列出ContactsContract.Contacts中的所有字段:
privatevoid listColumnNames()
{
private Uri contactUri =ContactsContract.Contacts.CONTENT_URI ;
ContentResolver resolver = this.getContentResolver();
Cursor cursor =resolver.query(contactUri, null, null, null, null);
int columnNumber = cursor.getColumnCount();
for(int i = 0; i <columnNumber; i++)
{
String temp =cursor.getColumnName(i);
Log.e("listColumnNames","" + i + "\t" + temp);
}
cursor.close();
}