public byte[] getPhoto(String people_id) { String photo_id = null; String selection1 = ContactsContract.Contacts._ID + " = " + people_id; Cursor cur1 = getContentResolver().query( ContactsContract.Contacts.CONTENT_URI, null, selection1, null, null); if (cur1.getCount() > 0) { cur1.moveToFirst(); photo_id = cur1.getString(cur1 .getColumnIndex(ContactsContract.Contacts.PHOTO_ID)); //System.out.println("photo_id:" + photo_id); } String[] projection = new String[] { ContactsContract.Data.DATA15 }; String selection = ContactsContract.Data._ID + " = " + photo_id; Cursor cur = getContentResolver().query( ContactsContract.Data.CONTENT_URI, projection, selection, null, null); cur.moveToFirst(); byte[] contactIcon = cur.getBlob(0); System.out.println("conTactIcon:" + contactIcon); if (contactIcon == null) { return null; } else { return contactIcon; } } 以下代码将字节数组转化成Bitmap对象,然后再ImageView中显示出来 private ImageView image; byte[] photo = getPhoto(contactId); Bitmap map = BitmapFactory.decodeByteArray(photo, 0, photo.length); image.setImageBitmap(map); |
获取联系人头像
最新推荐文章于 2021-05-26 06:06:48 发布