设为首页 加入收藏

TOP

Android 通过手机号查找联系人的头像
2014-11-24 03:27:14 来源: 作者: 【 】 浏览:1
Tags:Android 通过 手机号 查找 联系人 头像

/***
*
* @author lpYuqun
* @param context
* @param phoneNumber_MOBILE
* @return Bitmap
*
*/
public static Bitmap getAvatarByPhoneNumber(Context context,
String phoneNumber_MOBILE) {


Bitmap bitmap = null;


ContentResolver contentResolver = context.getContentResolver();


String projection[] = new String[] { Phone.CONTACT_ID, Phone.NUMBER };


phoneNumber_MOBILE = PhoneNumberUtils.formatNumber(phoneNumber_MOBILE);


Cursor cursor = contentResolver.query(Phone.CONTENT_URI, projection, // select
ContactsContract.CommonDataKinds.Phone.TYPE + "="
+ ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE
+ " and " + Phone.NUMBER + " = ", // where sentence
new String[] { phoneNumber_MOBILE }, // where values
null); // order by


if (cursor.moveToFirst()) {


String _contact_ID;
int _contact_ID_Column = cursor.getColumnIndex(Phone.CONTACT_ID);


_contact_ID = cursor.getString(_contact_ID_Column);


Uri contactPhotoUri = ContentUris.withAppendedId(
People.CONTENT_URI, Long.parseLong(_contact_ID));


InputStream is = People.openContactPhotoInputStream(
contentResolver, contactPhotoUri);
if (is != null) {
try {
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
return bitmap;
}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇编译Linux2.6.x内核步骤及注意事项 下一篇Android UI 界面绘制原理分析

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)
·Linux学习教程,Linu (2025-12-25 05:50:06)
·工业机器人TCP校准中 (2025-12-25 05:19:17)
·opc 通讯协议与 TCP (2025-12-25 05:19:15)