Problems with setPhotoData on contacts

All your problems with Audio, Video and Images.

Problems with setPhotoData on contacts

Postby exhuma » Sun Aug 30, 2009 11:01 am


I am currently writing my first Android app. I feel quite at home in Java, but here's one thing which puzzles me. I have written a small Activity which lets you import/export contacts. And I want the photos to be transported as well. To store the photos, I save them into the text file as Base64 encoded strings. I decode this string to store the photo in the restored contacts. I don't update the contacts however, but I recreate them (delete them all, and then recreate the from the dump file). It all works pretty well except the restoration of the photo. There's no error, no exception, but the photo remains empty. Here's what I do:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 JSONArray photos = contact.getJSONArray("photos");
  2.                 if ( photos.length() > 0 ) {
  3.                         String photo = photos.getString(0);
  4.                         if (photo != null && !photo.equals("") ){
  5.                                 try {
  6.                                         Contacts.People.setPhotoData(cr, uri, Base64.decode(photo));
  7.                                         System.out.println( "Added photo to " + uri );
  8.                                 } catch (IOException e) {
  9.                                         // TODO Auto-generated catch block
  10.                                         e.printStackTrace();
  11.                                 }
  12.                         }
  13.                 }
Parsed in 0.016 seconds, using GeSHi

A few details may be of interest:
  • This runs in a separate thread. When instantiating the thread, I pass a reference to the calling class (the Activity). The variable "cr" comes from "caller.getContentResolver()"
  • The IOException is never thrown (AFAICT)
  • I am using a third party Base64 class. But it works fine. I tried to use an encoded string on a laptop, decoded it with python and stored the result as JPEG image. The resulting file was correct.
  • I read the Android source of the method "setPhotoData" and tried to work from there without any luck.

Apparently this works for other people. So there must be something I am missing. Does anyone have any idea as to where I could look?
Once Poster
Once Poster
Posts: 1
Joined: Sun Aug 30, 2009 10:45 am


Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 7 guests