下面展示一段在Android1.5上读取手机通讯录的代码
1 //链接通讯录数据库
2 ContentResolver content = getContentResolver();
3 Cursor cursor = content.query(Contacts.People.CONTENT_URI, null, null, null, null);
4 //保存用户名信息
5 String[] nameList = new String[cursor.getCount()];
6 //遍历通讯录
7 for(int i=0; i<cursor.getCount() ;i++)
8 {
9 cursor.moveToPosition(i);
10 //获取人名
11 nameList[i] = cursor.getString(cursor.getColumnIndexOrThrow(Contacts.People.NAME));
12 //获取电话
13 nameList[i] += ":" + cursor.getString(cursor.getColumnIndexOrThrow(Contacts.People.NUMBER));
14 }
读取到的通讯录显示在一个ListView上边 如下图