API For 1.6 and Before 1.6之前的版本
Granting Access 授予权限
<uses-permission android:name="android.permission.READ_CONTACTS" />
Querying the contact database 联系人数据库查询
Retrieving Contact Details 获取联系方式
本的联系人信息存储在联系人表中,而详细信息存储在个人表中。在 Android1.x 中查询的联系人记录数据库的URI是People.CONTENT_URI。
package com.test;import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;import android.os.Bundle;
import android.provider.Contacts.People;
public class TestContacts extends Activity {
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(People.CONTENT_URI, null, null, null, null);
if(cur.getCount()>0){
while (cur.moveToNext()) {
String id = cur.getString(cur.getColumnIndex(People._ID));
String name = cur.getString(cur.getColumnIndex(People.DISPLAY_NAME));
}
}
}
}
Phone Numbers 电话号码
查询的URI换成Contacts.Phones.CONTENT_URI。
if (cur.getInt(cur.getColumnIndex(People.PRIMARY_PHONE_ID)) > 0) {
Cursor pCur = cr.query(Contacts.Phones.CONTENT_URI,null, Contacts.Phones.PERSON_ID +" = ?",new String[]{id}, null);
int i=0;
int pCount = pCur.getCount();
String[] phoneNum = new String[pCount]; String[] phoneType = new String[pCount];
while (pCur.moveToNext()) {
phoneNum[i] = pCur.getString(pCur.getColumnIndex(Contacts.Phones.NUMBER));
phoneType[i] = pCur.getString(pCur.getColumnIndex(Contacts.Phones.TYPE)); i++;
}
}
以存储多个电话号码,我们需要遍历返回的结果。查询除了返回电话号码外还返回了其他(家庭,工作,手机等)类型。
Email Addresses 邮件地址
Cursor emailCur = cr.query(Contacts.ContactMethods.CONTENT_EMAIL_URI,null, Contacts.ContactMethods.PERSON_ID + " = ?",new String[]{id}, null);
while (emailCur.moveToNext()) {
// This would allow you get several email addresses }
emailCur.close();
Notes 注释
为每个联系人附加自定义注释。注释存储在联系人记录中,并通过People.NOTES存储的数据进行访问。
String notes=cur.getString(cur.getColumnIndex(People.NOTES));
Postal Addresses 邮政地址
每个联系人都可以存储多个邮政地址。地址存储在联系方式表中,要获取数据,需要有次要条件。添加适配Contacts.ContactMethods.CONTENT_POSTAL_ITEM_TYPE的条件Contacts.ContactMethods.KIND来访问Contacts.ContactMethods.CONTENT_URI传递过来的地址。
String addrWhere = Contacts.ContactMethods.PERSON_ID + " = ? AND " + Contacts.ContactMethods.KIND + " = ?";
String[] addrWhereParams = new String[]{id, Contacts.ContactMethods.CONTENT_POSTAL_ITEM_TYPE}; Cursor addrCur = cr.query(Contacts.ContactMethods.CONTENT_URI, null, addrWhere, addrWhereParams, null); while(addrCur.moveToNext()) { String addr = addrCur.getString( addrCur.getColumnIndex(Contacts.ContactMethodsColumns.DATA)); String type = addrCur.getString( addrCur.getColumnIndex(Contacts.ContactMethodsColumns.TYPE)); } addrCur.close();
分享到:
相关推荐
android contacts qurey mode
android Contacts 源码eclipse编译Contacts 联系人 eclipse 源码此为android Contacts 联系人源码在eclipse编译的APK。 可以运行在 android4.4 以及一下的系统中,本人通过大量修改 直接安装运行即可。
基于Android4.4Contacts源码,不可独立运行
Android Contacts API. Quick Start Initialize Contacts Library public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Contacts.initialize(this); } ...
android4.1.1原生系统Contacts代码
Working With Android ContactsWorking With Android ContactsWorking With Android Contacts
Android Contacts之三自定义的联系人列表特效 A
Android Contacts之二根据4.4实现的联系人列表特效
android contacts源码,很好的学习参考材料
安卓Android源码——Contacts.rar
Android 源码分析_Contacts
android系统模块之Contacts的学习笔记
android4.0 Contacts 通讯录源码
Android 系统应用 联系人 Contacts 源码,2013年11月份下载
1.高效率读取联系人分组 2.高效率读取联系人列表(含有很酷的按字母分组的功能) 3.使用SQLLite存储 4.使用ksoap2调取webservice
实现了Contacts的滑动特效,中文索引,关键字搜索等等功能。
联系人列表的代码,可以参考学习
android_8.1、android go Contacts 谷歌原生代码。。。
android Contacts增删改查.docx