没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Introduction To Android Contacts
Learn to work with the Android contacts database. Basic knowledge of accessing SQLite in Android
along with using Cursors is expected. See theAndroid SQLite and Cursor Articlefor more information.
Google changed the contacts database moving from 1.x to 2.0 versions of Android. This tutorial will be
broken into 3 sections. First covering accessing contacts in Android 2.0. The second page will deal with
accessing the contacts in Android 1.6 and before. Third we'll glue it all together with a class that
abstracts specific classes for each version and a set of classes to manage the data from the contact
records.
Create a new project called TestContacts in Eclipse setup for Android 2.0.
Android Contact API For 2.0
Granting Access
Before an application can query the contact records access must be granted through the
AndroidManifest.xml file stored in the root of the project. Add the following uses-permission belows the
uses-sdk statement.
Querying The Android Contact Database
Retrieving Contact Details
Basic contact information stored in Contacts table with detailed information stored in individual tables for
normalization. In Android 2.0 to query the base contact records the URI to query is stored in
ContactsContract.Contacts.CONTENT_URI.
!"!"###$
##%#&$
#####'%$
##($
#)'$
#%####$
(''###*##%#&+
,,''-"#"#%#&.##,
/%
('%#0)'%1###2+
#0%1###2$
###3-0'$
##'%!###'%02$
4&0######516
''6''6''6''2$
70!##0282+
-"'0%*#022+
#!!##!0
!#'1*0######122$
#!!##!0
!#'1*0######19:;<22$
7
01#!1#0!##!0!#'1*0###
###=9=5<)22282+
>&""%*#
?
?
?
?
?
This application starts off as any other Android application. First create a ContentResolver isntance in
cr. Then use the ContentResolver instance to query the database and return a Cursor with the contacts
list. The query is perofrmed against the URI stored in ContactsContract.Contacts.CONTENT_URI. Next
check if the cursor contains records and if so loop through them. The record ID field is stored in the id
variable. This will be used as a where parameter later. Also the display name field is stored in the string
name. For more details about working with cursors seeAndroid Cursors Tutorial.
Phone Numbers
Phone numbers are stored in their own table and need to be queried separately. To query the phone
number table use the URI stored in the SDK variable
ContactsContract.CommonDataKinds.Phone.CONTENT_URI. Use a WHERE conditional to get the
phone numbers for the specified contact.
701#!1#0!##!0
!#'1*0######=9=5<)
22282+
4&0
#####@9"516
''6
#####@9"1AB6
-#!CD+?6''2$
-"'0%*#022+
#"!-#""
?
'02$
?
Perform a second query against the Android contacts SQLite database. The phone numbers are
queried against the URI stored in ContactsContract.CommonDataKinds.Phone.CONTENT_URI. The
contact ID is stored in the phone table as ContactsContract.CommonDataKinds.Phone.CONTACT_ID
and the WHERE clause is used to limit the data returned.
Email Addresses
Querying email addresses is similar to phone numbers. A query must be performed to get email
addresses from the database. Query the URI stored in
ContactsContract.CommonDataKinds.Email.CONTENT_URI to query the email address table.
'4&0
#####@'516
''6
#####@'1A
B6
-#!CD+?6''2$
-"'0'%*#022+
"-'''-&!#%''
7#"'-#&
#!''!##!0
'!#'1*0#####@
'22$
#!'&'!##!0
'!#'1*0#####@
';922$
?
''02$
As with the phone query the field names for the email table are also stored under
ContactsContract.CommonDataKinds. The email query is performed on the URI in
ContactsContract.CommonDataKinds.Email.CONTENT_URI and the WHERE clause has to match the
ContactsContract.CommonDataKinds.Email.CONTACT_ID field. Since multiple email addresses can be
stored loop through the records returned in the Cursor.
Notes
Custom notes can be attached to each contact record. As before these are stored in a separate table
and are related based on the contact ID.
#!#E"#####1A
BA#####<1<;9AB$
#!CD#E"9-#!CD+6
#####@#1<;9?$
#
4&0#####516''6#E"6
#E"96''2$
70#%F#022+
#!#
#!##!0#!#'1*0####
#@#22$
?
#'02$
Notes are stored in the Android Contacts generic data table. When accessing specific data the WHERE
clause will need 2 conditionals. First the standard contact ID, second a MIMETYPE for the data that is
being requested. The Android SDK comes with a series of auto-generated variables that take care of
this. Use the ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE variable to limit the
query to note records. The data table URI is stored at ContactsContract.Data.CONTENT_URI. Finally
the note field name is stored in ContactsContract.CommonDataKinds.Note.NOTE.
Postal Addresses
Android can store multiple postal addresses per contact. Addresses are also stored in the data table like
notes and queried via the URI stored in ContactsContract.Data.CONTENT_URI. Similar to the notes
query a MIMETYPE must be added to the WHERE conditional. Also in Android 2.0 the Address record
was split into multiple fields containing different parts of the address (PO-Box, stree, city, region, postal
code). In earlier versions of the Android SDK this was a free-form string storage.
#!E"#####1A
BA#####<1<;9AB$
#!CDE"9-#!CD+6
#####@##9#'1
<;9?$
4&0#####516
''6-"6-"9#6''2$
-"'0%*#022+
#!)*!##!0
!#'1*0#####@#
#9#'9)G22$
#!##!##!0
!#'1*0#####@#
#9#'22$
#!#&!##!0
!#'1*0#####@#
#9#'1;22$
#!##!##!0
!#'1*0#####@#
#9#'H122$
#!#'!##!0
!#'1*0#####@#
#9#'922$
#!#&!##!0
!#'1*0#####@#
#9#'5;22$
#!#&!##!0
!#'1*0#####@#
#9#';922$
?
'02$
剩余32页未读,继续阅读
资源评论
1234ag
- 粉丝: 6
- 资源: 58
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功