I'm happily retrieving contact photos with the new ContactsContract
APIs and cursor.getBlob, but I'm having great trouble working out how
to set a contact photo.
I believe I have the right URI (at least, it works for retrieving the
photo), but it just won't work for updating or adding one.
Here's my best bet:
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
Uri uri = Uri.withAppendedPath( ContactsContract.Contacts.CONTENT_URI,
friendId );
uri = Uri.withAppendedPath( uri,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
// eg: content://com.android.contacts/contacts/6/photo
ContentValues values = new ContentValues();
values.put(ContactsContract.CommonDataKinds.Photo.PHOTO,
bytes.toByteArray());
values.put(ContactsContract.CommonDataKinds.Photo.MIMETYPE,
ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE );
context.getContentResolver().insert(uri, values);
And here's my exception:
java.lang.UnsupportedOperationException: Unknown uri:
content://com.android.contacts/contacts/6/photo
at com.android.providers.contacts.LegacyApiSupport.update
(LegacyApiSupport.java:914)
at
com.android.providers.contacts.ContactsProvider2.updateInTransaction
(ContactsProvider2.java:2924)
at com.android.providers.contacts.SQLiteContentProvider.update
(SQLiteContentProvider.java:139)
at com.android.providers.contacts.ContactsProvider2.update
(ContactsProvider2.java:1923)
at android.content.ContentProvider$Transport.update
(ContentProvider.java:180)
at android.content.ContentProviderNative.onTransact
(ContentProviderNative.java:195)
at android.os.Binder.execTransact(Binder.java:287)
at dalvik.system.NativeStart.run(Native Method)
Any thoughts ?
Thanks,
Richard
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en