android获取手机通讯录联系人信息
private void getPhoneContacts() {
ContentResolver resolver = this.getContentResolver();
// 获取手机联系人
Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,
new String[] { Phone.CONTACT_ID, Phone.DISPLAY_NAME,
Phone.NUMBER },
Phone.DISPLAY_NAME + "=?" + " AND " + Phone.TYPE + "='"
+ Phone.TYPE_MOBILE + "'", new String[] { name }, null);
if (phoneCursor != null) {
while (phoneCursor.moveToNext()) {
String number = phoneCursor.getString(2);
// 当手机号码为空的或者为空字段 跳过当前循环
if (TextUtils.isEmpty(phoneNumber))
continue;
// 得到联系人名称
String username = phoneCursor.getString(1);
mContactsName.add(contactName);
mContactsNumber.add(phoneNumber);
}
phoneCursor.clo