Search code examples
androidandroid-layoutcontactscontractquickcontactbadge

Set QuickContactBadge image to contact's profile picture


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.


Solution

  • This will do it:

    InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), contactUri);
    badge.setImageBitmap(BitmapFactory.decodeStream(input));