I am creating a simple application that retrieves the name and phone number of each individual contact and display in a list view along with the contact\'s photo in a thumbn
You try to get the contact id of the contact(phonenumber) and use Bitmapfactory to decode the image as shown in below working code.
InputStream inputStream=null;
String[] projection = new String[]{Contacts._ID};
Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI,Uri.encode(phnumber));
Cursor c = getContentResolver().query(contactUri, projection,
null, null, null);
if (c.moveToFirst()) {
long contactId=c.getColumnIndex(Contacts._ID);
inputStream = Contacts.openContactPhotoInputStream(activity.getContentResolver(),
ContentUris.withAppendedId(Contacts.CONTENT_URI, cntID));
c.close();
}
use the inputstream to get bitmap
Bitmap bitmap= BitmapFactory.decodeStream(inputStream);
holder.ivPic.setImageBitmap(bitmap);