0
的Android 2.3.3獲取聯繫人
我發現下面的代碼在其中一個例子的照片...
String image = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI));
if (image != null) {
contactViewHolder.imgContact.setImageURI(Uri.parse(image));
} else {
contactViewHolder.imgContact
.setImageResource(R.drawable.addcontactsmall2);
}
但是,當我嘗試運行應用程序,它給了我IllegalStateException。然而,我沒有在其他地方找到這個URI。這是獲取聯繫人照片的正確方法嗎?
這是我所看到的,當我把我的光標移到PHOTO_URI :::
字符串android.provider.ContactsContract.ContactsColumns.PHOTO_URI = 「photo_uri」
public static final String PHOTO_URI
Added in API level 11
A URI that can be used to retrieve the contact's full-size photo.
If PHOTO_FILE_ID is not null, this will be populated with a URI based off CONTENT_URI.
Otherwise, this will be populated with the same value as PHOTO_THUMBNAIL_URI.
A photo can be referred to either by a URI (this field) or by ID (see PHOTO_ID).
If either PHOTO_FILE_ID or PHOTO_ID is not null, PHOTO_URI and PHOTO_THUMBNAIL_URI shall not be null (but not necessarily vice versa).
Thus using PHOTO_URI is a more robust method of retrieving contact photos.
Type: TEXT
Constant Value: "photo_uri"