Alex Bonel
Alex Bonel

Reputation: 1424

Storing contact photos with a possibility to retrieve original image in future

According to the official documentation which contains information about contact's photo handling (Android 4.0):

Large photos

Android now supports high resolution photos for contacts. Now, when you push a photo into a contact record, the system processes it into both a 96x96 thumbnail (as it has previously) and a 256x256 "display photo" that's stored in a new file-based photo store (the exact dimensions that the system chooses may vary in the future). You can add a large photo to a contact by putting a large photo in the usual PHOTO column of a data row, which the system will then process into the appropriate thumbnail and display photo records.

So, I would like to know if I store a photo with the size of 400x400 px, is there any possibility to retrieve this photo with it's original size, or I have to be glad only having a photo with decreased size?

Upvotes: 0

Views: 1365

Answers (2)

Mamoon Bakeer
Mamoon Bakeer

Reputation: 1

Simple solution:

  • Login to your gmail account from any PC, then search for "contacts"
  • From within contacts page: enter the contact name you want to search for
  • Click on the contact that you want & select "save image..."

Note: I don't know if there is a higher quality version inside the phone but I'm still working on it.

Upvotes: 0

Anton Klimov
Anton Klimov

Reputation: 379

Try this example:

 public void writeDisplayPhoto(long rawContactId, byte[] photo) {
     Uri rawContactPhotoUri = Uri.withAppendedPath(
             ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
             RawContacts.DisplayPhoto.CONTENT_DIRECTORY
     );

     try {
         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
             rawContactPhotoUri, 
             "rw"
         );

         OutputStream os = fd.createOutputStream();
         os.write(photo);

         os.close();
         fd.close();
     } catch (IOException e) {
         // Handle error cases.
     }
  }

Using file descriptors you can read/write contact photo. Also I think you need store thumbnail of your photo to contact

For more info see ContactsContract.RawContacts.DisplayPhoto class

Upvotes: 1

Related Questions