public static final String[] PHONES_PROJECTION = new String[]
{
Phone.DISPLAY_NAME,
Phone.NUMBER,
Photo.PHOTO_ID,
Phone.CONTACT_ID
};
public static final int PHONES_DISPLAY_NAME_INDEX = 0;
public static final int PHONES_NUMBER_INDEX = 1;
public static final int PHONES_PHOTO_ID_INDEX = 2;
public static final int PHONES_CONTACT_ID_INDEX = 3;
/**
* 获取联系人信息
*/
ContentResolver resolver = this.getContentResolver();
/**
* 获取手机联系人
*/
Cursor phoneCursor = resolver.query(Phone.CONTENT_URI,Parameters.PHONES_PROJECTION, null, null, null);
if (null != phoneCursor)
{
while (phoneCursor.moveToNext())
{
String phoneNumber = phoneCursor.getString(Parameters.PHONES_NUMBER_INDEX);// 得到手机号码
if (TextUtils.isEmpty(phoneNumber)) continue;// 当手机号码为空的或者为空字段 跳过当前循环
String contactName = phoneCursor.getString(Parameters.PHONES_DISPLAY_NAME_INDEX);// 得到联系人名称
String c_temp;
if (text_person.length() > contactName.length())
{
c_temp = PinyinUtil.hanziToPinyin(contactName,"").substring(0, contactName.length());
}
else
{
c_temp = PinyinUtil.hanziToPinyin(contactName,"").substring(0, text_person.length());
}
if (contactName.contains(text_person) ||
c_temp.contains(text_person))
{
diffrent = 1;
Contact contact = new Contact();
contact.setName(contactName);
contact.setNumber(phoneNumber);
list.add(contact);
break;
}
}
phoneCursor.close();
}