Code example for Context

Methods: getContentResolver

0
    if (uri == null) return getDefaultContactPhoto(context);
 
    Bitmap contactPhoto = localUserContactPhotoCache.get(uri);
 
    if (contactPhoto == null) {
      Cursor cursor = context.getContentResolver().query(uri, CONTENT_URI_PROJECTION,
                                                         null, null, null); 
 
      if (cursor != null && cursor.moveToFirst()) {
        contactPhoto = getContactPhoto(context, Uri.withAppendedPath(Contacts.CONTENT_URI,
                                       cursor.getLong(0) + ""));
      } else { 
        contactPhoto = getDefaultContactPhoto(context);
      } 
 
      localUserContactPhotoCache.put(uri, contactPhoto);
    } 
 
    return contactPhoto;
  } 
 
  public static void clearCache() { 
    localUserContactPhotoCache.clear();
  } 
 
  private static Bitmap getContactPhoto(Context context, Uri uri) {
    InputStream inputStream = ContactsContract.Contacts.openContactPhotoInputStream(context.getContentResolver(), uri);
 
    if (inputStream == null) return ContactPhotoFactory.getDefaultContactPhoto(context);
    else                     return BitmapFactory.decodeStream(inputStream);
  } 
}