I fixed the issue by changing the method below. I removed the AssetFileDescriptor and used a InputStream instead. This was in another question and works with my code.
/**
* Decodes and scales a contact's image from a file pointed to by a Uri in the contact's data,
* and returns the result as a Bitmap. The column that contains the Uri varies according to the
* platform version.
*
* @param photoData For platforms prior to Android 3.0, provide the Contact._ID column value.
* For Android 3.0 and later, provide the Contact.PHOTO_THUMBNAIL_URI value.
* @param imageSize The desired target width and height of the output image in pixels.
* @return A Bitmap containing the contact's image, resized to fit the provided image size. If
* no thumbnail exists, returns null.
*/
private Bitmap loadContactPhotoThumbnail(String photoData, int imageSize) {
// Ensures the Fragment is still added to an activity. As this method is called in a
// background thread, there's the possibility the Fragment is no longer attached and
// added to an activity. If so, no need to spend resources loading the contact photo.
if (!isAdded() || getActivity() == null) {
return null;
}
// Instantiates an AssetFileDescriptor. Given a content Uri pointing to an image file, the
// ContentResolver can return an AssetFileDescriptor for the file.
InputStream stream = null;
// This "try" block catches an Exception if the file descriptor returned from the Contacts
// Provider doesn't point to an existing file.
try {
Uri thumbUri;
// If Android 3.0 or later, converts the Uri passed as a string to a Uri object.
if (Utils.hasHoneycomb()) {
thumbUri = Uri.parse(photoData);
} else {
// For versions prior to Android 3.0, appends the string argument to the content
// Uri for the Contacts table.
final Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_URI, photoData);
// Appends the content Uri for the Contacts.Photo table to the previously
// constructed contact Uri to yield a content URI for the thumbnail image
thumbUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
}
stream = getActivity().getContentResolver().openInputStream(thumbUri);
return BitmapFactory.decodeStream(stream);
} catch (FileNotFoundException e) {
// If the file pointed to by the thumbnail URI doesn't exist, or the file can't be
// opened in "read" mode, ContentResolver.openAssetFileDescriptor throws a
// FileNotFoundException.
if (BuildConfig.DEBUG) {
Log.d(TAG, "Contact photo thumbnail not found for contact " + photoData
+ ": " + e.toString());
}
} finally {
// If an AssetFileDescriptor was returned, try to close it
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
// Closing a file descriptor might cause an IOException if the file is
// already closed. Nothing extra is needed to handle this.
}
}
}
// If the decoding failed, returns null
return null;
}