use code something like below to get contact id and use contact id to get image
Cursor phones = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, null, null,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
while (phones.moveToNext()) {
String name = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String phoneNumber = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
String ContactId = phones
.getString(phones
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID));
}
phones.close();
-------------------------------------------------
use below code to get contact image
ImageView imgPeople = new ImageView();
Uri my_contact_Uri = Uri.withAppendedPath(
ContactsContract.Contacts.CONTENT_URI,
String.valueOf(ContactId);
InputStream photo_stream = ContactsContract.Contacts
.openContactPhotoInputStream(
mContext.getContentResolver(), my_contact_Uri);
if (photo_stream != null) {
BufferedInputStream buf = new BufferedInputStream(
photo_stream);
Bitmap my_btmp = BitmapFactory.decodeStream(buf);
imgPeople.setImageBitmap(my_btmp);
}
No comments :
Post a Comment