I am making a autocomplete Field that queries contacts by Display name and Email. When someone clicks on the desired contact after the filtering that contact is added to a l
You should use RAW_CONTACT_ID in the query. For ex, there can be two different contacts i.e. different RAW_CONTACT_ID for a single CONTACT_ID.
When you want to access the photo of a contact, you need to specify the contact photo URI, for example using this method:
public Uri getContactPhotoUri(long contactId) {
Uri photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
photoUri = Uri.withAppendedPath(photoUri, ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
return photoUri;
}
But for contactId you must use:
String id = ContactsContract.CommonDataKinds.Photo.CONTACT_ID;
long contactId = Long.parseLong(id);
Please note that a common error is to use ContactsContract.Contacts._ID
instead ContactsContract.CommonDataKinds.Photo.CONTACT_ID
I hope that can help you.
maybe you can take a look at this blog post in the example there they query all contacts, email addresses and the contact photo http://blog.app-solut.com/2011/03/working-with-the-contactscontract-to-query-contacts-in-android/
best code will be
Uri photoUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Id);
Bitmap photoBitmap;
ContentResolver cr = getContentResolver();
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(cr, photoUri);
photoBitmap = BitmapFactory.decodeStream(is);
it works for all