Here, how to update or create profile images, in fact, it works the same way as updating regular contact images. I had a problem somewhere else ...
Instead of using my UserProfile, just replace them and pass the raw id.
private static void updatePhoto(UserProfile profile, Bitmap bitmap, ...) { byte[] photo = ImageUtil.convertImageToByteArray(bitmap, true); ContentValues values = new ContentValues(); int photoRow = -1; String where = ContactsContract.Data.RAW_CONTACT_ID + " = " + profile.getRawId() + " AND " + ContactsContract.Data.MIMETYPE + "=='" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'"; Cursor cursor = MainApp.get().getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, where, null, null); int idIdx = cursor.getColumnIndexOrThrow(ContactsContract.Data._ID); if (cursor.moveToFirst()) { photoRow = cursor.getInt(idIdx); } cursor.close(); values.put(ContactsContract.Data.RAW_CONTACT_ID, profile.getRawId()); values.put(ContactsContract.Data.IS_SUPER_PRIMARY, 1); values.put(ContactsContract.CommonDataKinds.Photo.PHOTO, photo); values.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE); if (photoRow >= 0) { MainApp.get().getContentResolver().update(ContactsContract.Data.CONTENT_URI, values, ContactsContract.Data._ID + " = " + photoRow, null); } else { MainApp.get().getContentResolver().insert(ContactsContract.Data.CONTENT_URI, values); } ... }
source share