Fetch the URI path to the contact’s thumbnail picture
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public static final String thumbnailByContactId(Context ctx, String contactId) { String uri = null; if (contactId != null) { ContentResolver cr = ctx.getContentResolver(); String[] projection = new String[] { ContactsContract.CommonDataKinds.Phone.PHOTO_URI, ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI }; Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, projection, ContactsContract.CommonDataKinds.Phone._ID + " = ?", new String[] { contactId }, null); String imageUri = null; String thumbnailUri = null; while (cur.moveToNext()) { imageUri = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI)); thumbnailUri = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_THUMBNAIL_URI)); } uri = thumbnailUri != null ? thumbnailUri : imageUri; } return uri; } |
Fetch the Bitmap for the URI path
1 2 3 4 5 6 7 8 9 10 11 12 |
public static final Bitmap uriToBitmap(Context ctx, String uri) { Bitmap bitmap = null; if (uri != null) { try { bitmap = MediaStore.Images.Media.getBitmap(ctx.getContentResolver(), Uri.parse(uri)); } catch (IOException e) { // Do nothing e.printStackTrace(); } } return bitmap; } |