联系人头像 android
16lz
2022-04-23
-
<preclass="java"name="code">ContentResolvercr=getContentResolver(); - Cursorcursor=cr.query(ContactsContract.Contacts.CONTENT_URI,null,"DISPLAY_NAME='"+"gm"+"'",null,
- null);
- if(cursor.moveToFirst()){
- //获得联系人的id
- StringcontactId=cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
- //修改联系人的头像
- BitmapsourceBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.img2);
- finalByteArrayOutputStreamos=newByteArrayOutputStream();
- //将Bitmap压缩成PNG编码,质量为100%存储
- sourceBitmap.compress(Bitmap.CompressFormat.PNG,100,os);
- byte[]avatar=os.toByteArray();
- ContentValuesvalues=newContentValues();
- values.put(Data.RAW_CONTACT_ID,contactId);
- values.put(Data.MIMETYPE,Photo.CONTENT_ITEM_TYPE);
- values.put(Photo.PHOTO,avatar);
- getContentResolver().update(Data.CONTENT_URI,values,null,null);</pre>
构建uri
- UricontactUri=ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI,
- Long.parseLong(contactId));
- //带路径
- UriphotoUri=Uri.withAppendedPath(contactUri,ContactsContract.Contacts.Photo.DATA15);
此uri为content://com.android.contacts/contactId/data15
获得联系人图片
- //获得联系人图片,读取的是Data类中的data15字段
- Uriuri=ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
- Long.parseLong(contactId));InputStreaminput=
- ContactsContract.Contacts.openContactPhotoInputStream(cr,uri);
- BitmapcontactPhoto=BitmapFactory.decodeStream(input);
- ImageViewimg=(ImageView)findViewById(R.id.img);
- img.setImageBitmap(contactPhoto);
查询电话记录
- //查询所有
- //Cursorcursor=resolver.query(CallLog.Calls.CONTENT_URI,null,
- //null,null,null);
- //查询指定号码
- Cursorcursor=resolver.query(CallLog.Calls.CONTENT_URI,null,
- "number=?andtype=?",newString[]{"15555215556","2"},null);
- while(cursor.moveToNext()){//取得联系人名字PhoneLookup.DISPLAY_NAMEintnameFieldColumnIndex
- =cursor.getColumnIndex(CallLog.Calls.CACHED_NAME);String
- contact=cursor.getString(nameFieldColumnIndex);
- //取得电话号码
- intnumberFieldColumnIndex=cursor.getColumnIndex(PhoneLookup.NUMBER);
- 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
更多相关文章
- android 获取屏幕大小
- Android下实现获取本机存储的联系人
- Android(安卓)图片透明度处理代码
- android 打开文件
- Android用Apache HttpClient 实现POST和Get请求
- android读取联系人信息(学习版)
- Android(安卓)SQLite数据库的添 删 查 改
- Android(安卓)获取联系人的姓名、电话信息
- android 使图片显示 圆角