How to correctly get photo of contact?
I have google contact linked with facebook contact (with photo) and skype contact (with photo).
I choose skype photo for contact (via address book application). Address book displays contact with chosen (skype) photo.
Start my app. Request photo id from ContactsContract.Contacts.CONTENT_URI by contact id. "Load" photo to ImageView. All seems well – photo has been loaded. Finish my app.
I choose facebook photo for contact (via address book application). Address book displays contact with chosen (facebook) photo.
Start my app. Again request photo id by contact id. The received photo id differs from the previous id. "Load" photo to ImageView. Photo has not been loaded. LogCat: "relolveUri failed on bad bitmap uri: ...". Why???
Some parts of my code:
Cursor photoCursor = managedQuery(
ContactsContract.Contacts.CONTENT_URI,
new String[]{ ContactsContract.Contacts.PHOTO_ID },
ContactsContract.Contacts._ID + "=?",
new String[]{ contactId },
null);
String photoId = photoCursor.getString(photoCursor.get开发者_运维知识库ColumnIndex(ContactsContract.Contacts.PHOTO_ID));
Uri photoUri = Uri.withAppendedPath(ContactsContract.Data.CONTENT_URI, photoIdByContatId);
ImageView imageView = (ImageView)findViewById(R.id.photo);
imageView.setImageURI(photoUri);
try this,
Cursor photoCursor = managedQuery(
new String[]{ContactsContract.Contacts._ID + "=?",
String.valueOf(ContactsContract.Contacts.Photo.MIMETYPE+ "=?")},
new String[]{contactId,
String.valueOf(ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE) }
null);
精彩评论