I am having a hard time understanding how to get information from a contact and also how to put information to a contact. Does anyone know of a good way to learn?
Anyways, to my main question. I got the contact image from some random code I found on the internet but now I want to set a new Bitmap image to my contact. What information do I need for the contact (URI or Contact_id) and it would be awesome if someone could give me a very basic and simple simple of code and kind of step though it. But if you don't have the time to step through it then just a basic code simple should be good. Thanks for any help.
EDIT GOT WORKING CODE NOW: This is the code that I used:
// Update picture to contact
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
//contactUriId is my contact URI with just contact id number at the end of the "content://..."
try
{
Bitmap bitmap = bmpNewContact;
ByteArrayOutputStream image = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG , 100, image);
Builder contentOp = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
contentOp.withSelection(ContactsContract.Data.CONTACT_ID + "=?" + " AND " + ContactsContract.Data.MIMETYPE + "=?", new String[]{String.valueOf(contactUriId), ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE});
contentOp.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, image.toByteArray());
ops.add(contentOp.build());
}
catch (Exception e)
{
e.printStackTrace();
}
// Update
try
{
getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
}
catch (Exception e)
{
e.printStackTrace();
}