How can I get the photo data (the blob of contact photo) if I have photo_ids
Can you please tell me how can I get the photo data if I have a 开发者_运维知识库list of photo_ids?
I try this:
cursor = mResolver.query(Contacts.Photos.CONTENT_URI, null, "_id IN (?)" , new String[] {"458"}, null);
But the cursor return null.
Any idea How to troubleshoot?
Thank you.
You can use the static method loadContactPhoto
to grab the photo for a contact..
Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, 458);
Bitmap contactPhoto = People.loadContactPhoto(_context, uri, R.drawable.unkown_contact, null);
if (null != contactPhoto) {
/* Your Magic Here */
}
Just to note, you will likely want to replace R.drawable.unkown_contact
with a resource you have for non-existent contact photos as well as replace _context
with an instance of a Context that you have.
The new api is
InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(cr, photo);
精彩评论