依次浏览你的电话本联系人
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while (cursor.moveToNext()) {
String contactId = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts._ID));
String hasPhone = cursor.getString(cursor.getColumnIndex(
ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (Boolean.parseBoolean(hasPhone)) {
// You know have the number so now query it like this
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,
null, null);
while (phones.moveToNext()) {
String phoneNumber = phones.getString(
phones.getColumnIndex(
ContactsContract.CommonDataKinds.Phone.NUMBER));
}
phones.close();
}
Cursor emails = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = " + contactId,
null, null);
while (emails.moveToNext()) {
// This would allow you get several email addresses
String emailAddress = emails.getString(
emails.getColumnIndex(
ContactsContract.CommonDataKinds.CommonDataColumns.DATA));
}
emails.close();
}
cursor.close();
得到电话本中的姓名和号码
Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
while(people.moveToNext()) {
int nameFieldColumnIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
String contact = people.getString(nameFieldColumnIndex);
int numberFieldColumnIndex = people.getColumnIndex(PhoneLookup.NUMBER);
String number = people.getString(nameFieldColumnIndex);
}
people.close();
如果你想得到一些 notes
private String getNote(long contactId) {
String note = null;
String[] columns = new String[]
{ ContactsContract.CommonDataKinds.Note.NOTE };
String where = ContactsContract.Data.RAW_CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
String[] whereParameters = new String[]{Long.toString(contactId),
ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE};
Cursor contacts = getContentResolver().query
(ContactsContract.Data.CONTENT_URI, projection, where,
whereParameters, null);
if (contacts.moveToFirst()) {
rv = contacts.getString(0);
}
contacts.close();
return note;
}
分享到:
相关推荐
Contacts简介 一个联系人列表,汉字转拼音的Android实现 运行截图 开源协议 Copyright (C) 2014, 张涛 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in...
<uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission....
中间件层包括函数库,由java开发,android操作系统、中间件、用户界面和应用软件组成。 最佳分辨率: 1440x900 最佳浏览器: 火狐Firefox ------------------------------ EML企业通讯录管理系统 v2.0版本 ------------...
16.3.5 关于变换矩阵的一些说明 16.4 资源 16.5 小结 第17章 地图和基于位置的服务 17.1 地图包 17.1.1 从Google获取map-api密钥 17.1.2 MapView和MapActivity 17.1.3 使用覆盖图添加标记 ...
16.3.5 关于变换矩阵的一些说明 16.4 资源 16.5 小结 第17章 地图和基于位置的服务 17.1 地图包 17.1.1 从Google获取map-api密钥 17.1.2 MapView和MapActivity 17.1.3 使用覆盖图添加标记 ...
## Contacts如果您对代码有任何疑问,或者想向我建议一些改进,可以与我联系或加入Survivig with Android社区。 ##许可证版权所有2012-2014 Francesco Azzola(使用Android生存) 根据Apache许可证2.0版(“许可...
##截图 ##Credits作者: Francesco Azzola(JFrankie)( )跟随 Android 生存 ##Contacts 如果您对代码有任何疑问或想向我提出一些改进建议,您可以联系我或加入 Survivig with Android 社区。 ##Licence 版权...
In version 4, there are significant updates to the platform including the release of Xamarin.Forms 2.0, and improvements have been made to the iOS and Android designers. With Xamarin being acquired ...
##Contacts 如果您对代码有任何疑问或想向我提出一些改进建议,您可以联系我或加入 Survivig with Android 社区。 ##Licence 版权所有 2012-2014 Francesco Azzola(使用 Android 生存) 根据 Apache 许可,...
编写该文件以支持VCF 2.0、2.1、3.0和4.0格式的文件(包括具有可打印编码(MIME)的文件),并已通过Backupify,Google Contacts(Gmail Contacts),Apple IOS,Samsung Android设备和其他设备的大量VCF文件进行了...