How Do I Display A Contact's Photo From The Contact's Id?
This code (within my CustomAdapter class) displays only the contact id based on the who sent me text messages and puts them into an ArrayList, then displays the list. I have a Imag
Solution 1:
try this..
publicvoidgetContacts(ContentResolver cr) {
Cursorphones= cr.query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null,
null, null);
while (phones.moveToNext()) {
Stringname= phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
StringcontactId= phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
Bitmapbitmap= loadContactPhoto(
getContentResolver(), Long.valueOf(contactId))
}
phones.close();
get Bitmap image
publicstatic Bitmap loadContactPhoto(ContentResolver cr, long id) {
Uriuri= ContentUris.withAppendedId(
ContactsContract.Contacts.CONTENT_URI, id);
InputStreaminput= ContactsContract.Contacts
.openContactPhotoInputStream(cr, uri);
if (input == null) {
returnnull;
}
return BitmapFactory.decodeStream(input);
}
Post a Comment for "How Do I Display A Contact's Photo From The Contact's Id?"