【发布时间】:2014-11-30 12:54:37
【问题描述】:
问题:我无法通过相机拍摄的照片更新联系人的缩略图。 环境:模拟器,api19
我的代码:
String where = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?";
ArrayList<android.content.ContentProviderOperation> ops = new ArrayList<android.content.ContentProviderOperation>();
String[] photoParams = new String[] { String.valueOf(contact.getPhoneContactId()),
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE };
Bitmap bitmap = MediaStore.Images.Media.getBitmap(contentResolver, Uri.parse(contact.getPhoto()));
ByteArrayOutputStream image = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG , 100, image);
ops.add(android.content.ContentProviderOperation
.newUpdate(android.provider.ContactsContract.Data.CONTENT_URI).withSelection(where, photoParams)
.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, image.toByteArray()).build());
contentResolver.applyBatch(ContactsContract.AUTHORITY, ops);
联系人缩略图既不会显示在本机联系人应用程序中,也不会通过编程方式拉出
ContentResolver cr = getActivity().getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
Uri imageUri = null;
if (cur.getString(cur.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)) != null)
imageUri = Uri.parse(cur.getString(cur
.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)));
InputStream is = null;
try {
if (imageUri != null)
is = getActivity().getContentResolver().openInputStream(imageUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
感谢任何关于为什么这有效(或者更确切地说不有效)的想法。
【问题讨论】:
标签: android android-contentprovider android-contentresolver contactscontract