联系人头像 android


  1. <preclass="java"name="code">ContentResolvercr=getContentResolver();
  2. Cursorcursor=cr.query(ContactsContract.Contacts.CONTENT_URI,null,"DISPLAY_NAME='"+"gm"+"'",null,
  3. null);
  4. if(cursor.moveToFirst()){
  5. //获得联系人的id
  6. StringcontactId=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
  7. //修改联系人的头像
  8. BitmapsourceBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.img2);
  9. finalByteArrayOutputStreamos=newByteArrayOutputStream();
  10. //将Bitmap压缩成PNG编码,质量为100%存储
  11. sourceBitmap.compress(Bitmap.CompressFormat.PNG,100,os);
  12. byte[]avatar=os.toByteArray();
  13. ContentValuesvalues=newContentValues();
  14. values.put(Data.RAW_CONTACT_ID,contactId);
  15. values.put(Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE);
  16. values.put(Photo.PHOTO,avatar);
  17. getContentResolver().update(Data.CONTENT_URI,values,null,null);</pre>

构建uri


  1. UricontactUri=ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI,
  2. Long.parseLong(contactId));
  3. //带路径
  4. UriphotoUri=Uri.withAppendedPath(contactUri,ContactsContract.Contacts.Photo.DATA15);

此uri为content://com.android.contacts/contactId/data15

获得联系人图片

  1. //获得联系人图片,读取的是Data类中的data15字段
  2. Uriuri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
  3. Long.parseLong(contactId));InputStreaminput=
  4. ContactsContract.Contacts.openContactPhotoInputStream(cr,uri);
  5. BitmapcontactPhoto=BitmapFactory.decodeStream(input);
  6. ImageViewimg=(ImageView)findViewById(R.id.img);
  7. img.setImageBitmap(contactPhoto);

查询电话记录

  1. //查询所有
  2. //Cursorcursor=resolver.query(CallLog.Calls.CONTENT_URI,null,
  3. //null,null,null);
  4. //查询指定号码
  5. Cursorcursor=resolver.query(CallLog.Calls.CONTENT_URI,null,
  6. "number=?andtype=?",newString[]{"15555215556","2"},null);
  7. while(cursor.moveToNext()){//取得联系人名字PhoneLookup.DISPLAY_NAMEintnameFieldColumnIndex
  8. =cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);String
  9. contact=cursor.getString(nameFieldColumnIndex);
  10. //取得电话号码
  11. intnumberFieldColumnIndex=cursor.getColumnIndex(PhoneLookup.NUMBER);
  12. Stringnumber=cursor.getString(numberFieldColumnIndex);

取得浏览器所有“书签”信息:content://browser/bookmarks

数据都存储在contract的data表中,每一个联系人项存储一行

另有两篇:一篇讲解contentProvider

http://www.cnblogs.com/not-code/archive/2011/06/24.html

另一篇讲解联系人

http://blog.csdn.net/wenlin56/article/details/6074437

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值