如何更新没有图片的联系人图片

时间:2013-08-08 08:19:52

标签: android android-contacts

已经问了一个但没有答案。如何更新已经没有图片的联系人的图片。代码是。

if(check_image == null) {

                        Bitmap bmImage = BitmapFactory.decodeFile(picturePath);
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        bmImage.compress(Bitmap.CompressFormat.JPEG, 80, baos);
                        byte[] b = baos.toByteArray();
                        Toast.makeText(getApplicationContext(), "if", Toast.LENGTH_LONG).show();

                        ops.add(ContentProviderOperation
                                .newInsert(
                                        ContactsContract.Data.CONTENT_URI)
                                .withValueBackReference(
                                        ContactsContract.Data.RAW_CONTACT_ID,
                                        0)
                                .withValue(
                                        ContactsContract.Data.MIMETYPE,
                                        ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                                .withValue(
                                        ContactsContract.CommonDataKinds.Photo.DATA15,
                                        b).build());
                    }
                    else {
                        Toast.makeText(getApplicationContext(), "else", Toast.LENGTH_LONG).show();
                        ops.add(ContentProviderOperation
                                .newUpdate(ContactsContract.Data.CONTENT_URI)
                                .withSelection(
                                        ContactsContract.Data.CONTACT_ID
                                                + " = ? AND "
                                                + ContactsContract.Data.MIMETYPE
                                                + " = ?",
                                        new String[] {
                                                contactid,
                                                ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE })
                                .withValue(Photo.DATA15, image_byte).build());
                    }

0 个答案:

没有答案