你好,游客 登录 注册 搜索
背景:
阅读新闻

Android通过查询电话号码获取联系人头像

[日期:2012-07-04] 来源:Linux社区  作者:yhm2046 [字体:大 中 小]

Android通过查询电话号码获取联系人头像:

  1. // 取得Intent中的頭像   
  2.             ivShowImage = (ImageView) findViewById(R.id.call_log_detail_contact_img);  
  3.             //通话电话号码获取头像uri   
  4.             Uri uriNumber2Contacts = Uri  
  5.                     .parse("content://com.android.contacts/"  
  6.                             + "data/phones/filter/" + strPhoneNumber);  
  7.             Cursor cursorCantacts = SApplication.nowSApplication  
  8.                     .getContentResolver().query(uriNumber2Contacts, null, null,  
  9.                             null, null);  
  10.             if (cursorCantacts.getCount() > 0) { //若游标不为0则说明有头像,游标指向第一条记录   
  11.                 cursorCantacts.moveToFirst();  
  12.                 Long contactID = cursorCantacts.getLong(cursorCantacts  
  13.                         .getColumnIndex("contact_id"));  
  14.                 Uri uri = ContentUris.withAppendedId(  
  15.                         ContactsContract.Contacts.CONTENT_URI, contactID);  
  16.                 InputStream input = ContactsContract.Contacts  
  17.                         .openContactPhotoInputStream(  
  18.                                 SApplication.nowSApplication  
  19.                                         .getContentResolver(), uri);  
  20.                 btContactImage = BitmapFactory.decodeStream(input);  
  21.                 Log.i("info", "bt======" + btContactImage);  
  22.                 ivShowImage.setImageBitmap(btContactImage);  
  23.   
  24.             } else {//么有头像设置默认头像   
  25.                 ivShowImage  
  26.                         .setImageResource(R.drawable.call_log_contact_image2);  
  27.   
  28.             }  
linux
相关资讯       Android开发入门 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留��删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款