ContactsContract.CommonDataKinds.Email.PHOTO_URI
您可以在不使用这种方式的情况下获取联系人照片 uri :
private Uri getPhotoUriFromEmail(String email) {
Uri u = null;
String[] projection = { ContactsContract.CommonDataKinds.Photo.CONTACT_ID };
String photoUri;
ContentResolver cr = getContentResolver();
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
projection,
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
new String[]{email}, null);
if (emailCur.moveToNext()) {
int columnIndex = emailCur.getColumnIndex(
ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
long contactId = emailCur.getLong(columnIndex);
u = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
contactId);
u = Uri.withAppendedPath(u,
ContactsContract.Contacts.Photo.CONTENT_DIRECTORY);
}
return u;
}
或者,您可以通过以下方式获取照片流ContactsContract.Contacts .openContactPhotoInputStream(ContentResolver, Uri)
:
private InputStream getPhotoInputStreamFromEmail(String email) {
Uri u = null;
String[] projection = { ContactsContract.CommonDataKinds.Photo.CONTACT_ID };
String photoUri;
ContentResolver cr = getContentResolver();
Cursor emailCur = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
projection,
ContactsContract.CommonDataKinds.Email.ADDRESS + " = ?",
new String[]{email}, null);
if (emailCur.moveToNext()) {
int columnIndex = emailCur.getColumnIndex(
ContactsContract.CommonDataKinds.Photo.CONTACT_ID);
long contactId = emailCur.getLong(columnIndex);
u = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
contactId);
return ContactsContract.Contacts.openContactPhotoInputStream(cr, u);
}
return null;
}