On Aug 29, 2:49 pm, Michel Albert <[email protected]> wrote:
> Hmmm... I am trying the same thing. The method with "setPhotoData"
> does indeed run without a hitch. Except that the photo does not show
> on the contact when displaying it with the default "Contacts"
> application. I double checked both the Uri and the bytearray. Both are
> perfectly fine. The whole thing runs in a separate thread. Upon
> instantiation of the thread, I pass the Activity which started the
> thread as parameter. This is the "mParent" variable. Could it have
> something to do with that?
>
>                 JSONArray photos = contact.getJSONArray("photos");
>                 if ( photos.length() > 0 ) {
>                         String photo = photos.getString(0);
>                         if (photo != null ){
>                                 try {
>                                         
> Contacts.People.setPhotoData(mParent.getContentResolver(), uri,
> Base64.decode(photo));
>                                         System.out.println( "Added to " + uri 
> );
>                                 } catch (IOException e) {
>                                         // TODO Auto-generated catch block
>                                         e.printStackTrace();
>                                 }
>                         }
>                 }
>
> On Jul 24, 6:32 pm, Serkan Ozel <[email protected]> wrote:
>
> > Yes, People.setPhotoDataworked, 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.setPhotoDatato 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 -
>
>

I got it! For some reason it does not work on the emulator. But when
the app runs on the phone it works. Two whole days los for that.... -_-
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to