简体   繁体   中英

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.

This will do it:

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM