//获取联系人的姓名、电话信息 public List<ContactInfo> getContact() {                          //取得ContentResolver         ContentResolver content = getContentResolver();                                          Uri uri = ContactsContract.Contacts.CONTENT_URI;                //联系人的URI         Cursor cursor = content.query(uri,null, null, null, null);         int contactCount = cursor.getCount();                //获得联系人数目           List<ContactInfo> contacts = new ArrayList<ContactInfo>(contactCount);                    if (cursor.moveToFirst())         {                 // 循环遍历                 for (;!cursor.isAfterLast();cursor.moveToNext())                 {                         List<String> allPhoneNum = null;                         ContactInfo contact = new ContactInfo();                                                                   int idColumn = cursor.getColumnIndex(ContactsContract.Contacts._ID);                         int displayNameColumn = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);                         int phoneColumn = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);                                                                    // 获得联系人的ID号                         String contactId = cursor.getString(idColumn);                         contact.setContactId(contactId);                         // 获得联系人姓名                         String disPlayName = cursor.getString(displayNameColumn);                         contact.setContactName(disPlayName);                                           // 电话号码的个数                         //String phoneString = cursor.getString(phoneColumn);                         int phoneNum = cursor.getInt(phoneColumn);                                                                           if (phoneNum > 0)                         {                                 // 获得联系人的电话号码的cursor;                                 Cursor phones = content.query(                                                 ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,  ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ " = " + contactId,   null, null);     int phoneCount = phones.getCount();                                 allPhoneNum = new ArrayList<String>(phoneCount);                                 if (phones.moveToFirst())                                 {                                         // 遍历所有的电话号码                                         for (;!phones.isAfterLast();phones.moveToNext())                                         {                                                                                                  String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));                                                 allPhoneNum.add(phoneNumber);                                         }                                                                           if (!phones.isClosed())                                         {                                                 phones.close();                                         }                                 }                         }                                           contact.setContactPhone(allPhoneNum);                         contacts.add(contact);                 }                           if (!cursor.isClosed())                 {                         cursor.close();                 }         }         return contacts; }public class ContactInfo{ private String contactId; private String contactName; private List<String> contactPhone;  public String getContactId() {         return contactId; }  public String getContactName() {         return contactName; }  public List<String> getContactPhone() {         return contactPhone; }  public void setContactId(String id) {         contactId = id; }  public void setContactName(String name) {         contactName = name; }  public void setContactPhone(List<String> phone) {         contactPhone = phone; }}

更多相关文章

  1. Android(安卓)图片透明度处理代码
  2. android读取联系人信息(学习版)
  3. Android(安卓)SQLite数据库的添 删 查 改
  4. android 使图片显示 圆角
  5. Android在onCreate()中获得控件尺寸 (转)
  6. android 权限库,拿来就能用
  7. Android读取联系人的姓名及号码
  8. android 关于联系人列表的一个类
  9. Android(安卓)获得当前进程PackageName

随机推荐

  1. [Android] patchrom的随笔(个人运行记录..
  2. android查看程序运行内存
  3. Android Zxing修改二维码中扫描框的大小
  4. android 程序框架--资源和资产
  5. mac 下配置ANDROID_HOME环境变量
  6. android退出程序 后台运行 实现退出键和h
  7. Android运行时异常“Binary XML file lin
  8. android中在切换fragment时,怎样做到无需
  9. android 开发常用代码备查[更新20150520]
  10. http://www.jb51.net/article/37855.htm