Frage

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.

War es hilfreich?

Lösung

This will do it:

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

Andere Tipps

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)
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top