我无法通过我的应用为联系人设置图片。现有图像被替换但我不能将图片添加到新图像。任何人都可以帮忙!提前致谢 这是代码
try {
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 75, stream);
android.content.ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContactsContract.Data.CONTENT_URI);
builder.withSelection(
ContactsContract.Data.CONTACT_ID + "=?" + " AND "
+ ContactsContract.Data.MIMETYPE + "=?",
new String[] {
String.valueOf(contactId),
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE });
builder.withValue(
ContactsContract.CommonDataKinds.Photo.PHOTO,
stream.toByteArray());
ops.add(builder.build());
getContentResolver().applyBatch(ContactsContract.AUTHORITY,
ops);
}
catch (Exception e) {
e.printStackTrace();
}
case R.id.assign_contact:
cropstatus = 2;
filepath = Environment.getExternalStorageDirectory().getPath()
+ "/Noredoo/Profile Pictures/" + file.getName();
startCropImage(filepath, 1, 1);
Intent contactintent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(
Intent.createChooser(contactintent, "Choose Contact"),
PICK_CONTACT);
return true;
答案 0 :(得分:0)
尝试
ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);