/**
* 查询所有联系人信息
* 这里查询的是data表
*
*/
@SuppressLint("NewApi")
private void findContack() {
ContentResolver cr = this.getContentResolver();
Cursor cur = cr.query(Data.CONTENT_URI, null, null, null, "raw_contact_id");
int oldId = -1;
while(cur.moveToNext()){
int newId = cur.getInt(cur.getColumnIndex(Data.RAW_CONTACT_ID));
//新的联系人 外键发生改变了
if(oldId != newId ){
oldId = newId;
}
//取得当前记录的类型
String mimeType = cur.getString(cur.getColumnIndex(Data.MIMETYPE));
//取得名称相关
if(StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)){
String familyName = cur.getString(cur.getColumnIndex(StructuredName.FAMILY_NAME)); //姓
String givenName = cur.getString(cur.getColumnIndex(StructuredName.GIVEN_NAME)); //名
mContactsName.add(givenName);
// //绘制联系人名称
// title.setText(mContactsName.get(position));
// //绘制联系人号码
// text.setText(mContactsNumber.get(position));
// //绘制联系人头像
// iamge.setImageBitmap(mContactsPhonto.get(position));
Bitmap contactPhoto = null;
Long contactid = cur.getLong(cur.getColumnIndex(StructuredName.CONTACT_ID));
Long photoid = cur.getLong(cur.getColumnIndex(StructuredName.PHOTO_ID));
if(photoid > 0 ) {
Uri uri =ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,contactid);
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
contactPhoto = BitmapFactory.decodeStream(input);
}else {
contactPhoto = BitmapFactory.decodeResource(getResources(), R.drawable.contact_photo);
}
mContactsPhonto.add(contactPhoto);
}
//取得电话相关
else if(Phone.CONTENT_ITEM_TYPE.equals(mimeType)){
int phoneType = cur.getInt(cur.getColumnIndex(Phone.TYPE));
//宅电信息 家庭电话
if(phoneType == Phone.TYPE_HOME){
// p.homeTel = cur.getString(cur.getColumnIndex(Phone.NUMBER));
}
//手机信息
else if(phoneType == Phone.TYPE_MOBILE){
String mobileTel = cur.getString(cur.getColumnIndex(Phone.NUMBER));
mContactsNumber.add(mobileTel);
}
}
//取得及时(im)信息 msn qq
else if(Im.CONTENT_ITEM_TYPE.equals(mimeType)){
int imType = cur.getInt(cur.getColumnIndex(Im.PROTOCOL));
//msn
if(imType == Im.PROTOCOL_MSN){
// p.msn = cur.getString(cur.getColumnIndex(Im.DATA));
}
else if(imType == Im.PROTOCOL_QQ){
String qq = cur.getString(cur.getColumnIndex(Im.DATA));
Log.i("DD","===qq===="+qq);
}
}
}
}