Home » Android » Android – openContactPhotoInputStream returns NULL for all contact photo IDs

Android – openContactPhotoInputStream returns NULL for all contact photo IDs

Posted by: admin June 15, 2020 Leave a comment

Questions:

After upgrading to Android 4.0 ICS, my app, which contains a contact list with images, stopped loading images for those contacts.

After debugging it seems the following line always returns NULL now.

 InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);

I haven’t changed the application at all, right after upgrading to ICS this started happening.

I have the permission READ_CONTACTS.

Does anyone know why this could happen? What could they have changed? Is this method deprecated or something?

The full code:

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);
}
How to&Answers: