2

I'm using a QuickContactBadge and want it to display the contact's profile picture. This is how I'm loading the contact info:

Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId));
    QuickContactBadge badge = (QuickContactBadge) findViewById(R.id.badge);
    badge.setMode(ContactsContract.QuickContact.MODE_LARGE);
    badge.assignContactUri(contactUri);

What would be the simplest way? Thanks.

Henrique
  • 4,921
  • 6
  • 36
  • 61

2 Answers2

4

This will do it:

InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), contactUri);
badge.setImageBitmap(BitmapFactory.decodeStream(input));
Henrique
  • 4,921
  • 6
  • 36
  • 61
  • Is it also possible to get the facebook profile picture in the badge? I'm getting the error isQmage : stream is not a Qmage file – Diego Nov 21 '14 at 04:41
0

You don't need to manage the bitmap yourself. Just take the photoUri from the ContactsContract.Contacts content provider (the same where you get the contactId)

Uri photoUri = Uri.parse(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI))
badge.setImageURI(photoUri)
Santacrab
  • 3,165
  • 2
  • 25
  • 31