设为首页 加入收藏

TOP

Android 通过手机号查找联系人的头像
2014-11-24 03:27:14 来源: 作者: 【 】 浏览:0
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 界面绘制原理分析

评论

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

·常用meta整理 | 菜鸟 (2025-12-25 01:21:52)
·SQL HAVING 子句:深 (2025-12-25 01:21:47)
·SQL CREATE INDEX 语 (2025-12-25 01:21:45)
·Shell 传递参数 (2025-12-25 00:50:45)
·Linux echo 命令 - (2025-12-25 00:50:43)