Yes, People.setPhotoData worked, thanks.
Here is what I ended up doing - I hope others can also benefit from
this.
Bitmap photo = myImage.getBitmap();
if (photo != null) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);
People.setPhotoData(getContentResolver(), uri, stream.toByteArray
());
}
On Jul 24, 1:22 am, quill <[email protected]> wrote:
> Use Contacts.People.setPhotoData to insert a photo.
>
> On Jul 23, 9:21 pm, Serkan Ozel <[email protected]> wrote:
>
>
>
> > Hello Friends,
>
> > I was wondering if anyone has been able to accomplish this.
>
> > I'm able to insert entries into contacts (from my app) with name,
> > phone and email however I can't seem to add a photo to these
> > entries.
>
> > This works:
> > ContentValues values = new ContentValues();
> > values.put(People.NAME, "Serkan Ozel");
> > Uri uri = getContentResolver().insert(People.CONTENT_URI, values);
>
> > continuing this fails:
> > photoUri = Uri.withAppendedPath(uri,
> > Contacts.Photos.CONTENT_DIRECTORY);
> > values.clear();
> > values.put(Contacts.Photos.DATA, image.getByteArray());
> > getContentResolver().insert(photoUri, values);
>
> > This is the stack trace:
> > java.lang.UnsupportedOperationException: Cannot insert into URL:
> > content://contacts/people/36/photo
> > at android.database.DatabaseUtils.readExceptionFromParcel
> > (DatabaseUtils.java:131)
> > at android.database.DatabaseUtils.readExceptionFromParcel
> > (DatabaseUtils.java:111)
> > at android.content.ContentProviderProxy.insert
> > (ContentProviderNative.java:340)
> > at android.content.ContentResolver.insert(ContentResolver.java:476)
>
> > Any help would be appreciated.
>
> > Thanks- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---