0

I would like to get the uncropped contact image photo to set as full screen image background on Android 2.0 upwards. I use the following code to get a cropped thumbnail but as the photo is full screen in the gallery, how do I get access to this photo

This code gives cropped thumbnail, how do I get uncropped full screen

       public static Bitmap loadContactPhoto(ContentResolver cr, long  id) {
        Uri uri =             ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id);
        InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
        if (input == null) {
            return null;
        }
        return BitmapFactory.decodeStream(input);
    }
tech74
  • 301
  • 5
  • 20

1 Answers1

1

Android Documentation says

A read-only sub-directory of a single contact that contains the contact's primary photo. The photo may be stored in up to two ways - the default "photo" is a thumbnail-sized image stored directly in the data row, while the "display photo", if present, is a larger version stored as a file.

Again from documentation

public InputStream openDisplayPhoto(long contactId) {
     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
     Uri displayPhotoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.DISPLAY_PHOTO);
     try {
         AssetFileDescriptor fd =
             getContentResolver().openAssetFileDescriptor(displayPhotoUri, "r");
         return fd.createInputStream();
     } catch (IOException e) {
         return null;
     }
 }
Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
  • Contacts is deprecated need to use ContactsContract API v5 and above then can't see a way to get the hi-res image until api 14 which has some apis to easily get it but how about for phones running Android 2.0-2.3 – tech74 May 27 '12 at 10:00
  • If you could not find anything I suggest you use it, you can upgrade your app with a new version when the Contacts is finally removed. A discussion about `deprecated' here http://stackoverflow.com/questions/10297293/andorid-how-can-i-replace-the-deprecated-tabhost might be useful. – Gaurav Agarwal May 27 '12 at 10:52
  • apologies the DISPLAY_PHOTO field you have above is only API 14 and above so looks like prior to V4.0 there is only the thumbnail – tech74 May 27 '12 at 18:49
  • You are right, it is introduced in v4.0 here you go...http://developer.android.com/sdk/android-4.0.html – Gaurav Agarwal May 27 '12 at 18:59