Android 为什么我的联系人照片不显示在listview中? 需要注意的是,IM使用的API是2.3
我有一个列表视图,当前由在我的设备收件箱中向我发送文本消息的联系人(当前为6名)填充。收集所有联系人并将其传递到Android 为什么我的联系人照片不显示在listview中? 需要注意的是,IM使用的API是2.3,android,listview,photo,contact,Android,Listview,Photo,Contact,我有一个列表视图,当前由在我的设备收件箱中向我发送文本消息的联系人(当前为6名)填充。收集所有联系人并将其传递到ArrayList后,ArrayList将被传递到myCustomAdapter类的构造函数中。从这里开始,这是在我的getView()方法中用收件箱中的联系人填充我的listview的代码: holder.photo = (ImageView) rowView.findViewById(R.id.iv_contactPic); holder.contact = (TextView)
ArrayList
后,ArrayList将被传递到myCustomAdapter类的构造函数中。从这里开始,这是在我的getView()
方法中用收件箱中的联系人填充我的listview的代码:
holder.photo = (ImageView) rowView.findViewById(R.id.iv_contactPic);
holder.contact = (TextView) rowView
.findViewById(R.id.contactEntryText);
String folder = "content://sms/inbox/";
Uri mSmsQueryUri = Uri.parse(folder);
contactID = new ArrayList<String>();
try {
c = context.getContentResolver().query(mSmsQueryUri,
new String[] { "_id", "address", "date", "body" },
null, null, null);
if (c == null) {
Log.i(TAG, "cursor is null. uri: " + mSmsQueryUri);
}
c.moveToFirst();
while (c.moveToNext()) {
cid = c.getString(0);
contactID.add(cid); // stores contact IDs
}
} catch (Exception e) {
//Log.e(TAG, e.getMessage());
} finally {
c.close();
}
if(holder != null){
holder.contact.setText(data.get(position)); // displays contact by name
//Contact photo not showing
holder.photo.setImageBitmap(getByteContactPhoto(contactID.get(position));
}
但在LogCat中,这是唯一显示照片的内容:
public Bitmap getByteContactPhoto(String contactId) {
Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, Long.parseLong(contactId));
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
Cursor cursor = context.getContentResolver().query(photoUri,
new String[] {Contacts.Photo.DATA15}, null, null, null);
if (cursor == null) {
return null;
}
try {
cursor.moveToFirst();
if (cursor.moveToNext()) {
byte[] data = cursor.getBlob(0);
if (data != null) {
return BitmapFactory.decodeStream( new ByteArrayInputStream(data));
}
}
} finally {
cursor.close();
}
return null;
}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
W/Resources(15031): Converting to string: TypedValue{t=0x12/d=0x0 a=3 r=0x7f080015}
有没有办法解决这个问题,以便显示联系人照片?您确定
数据的内容是一个ByteArray图像吗?@Graeme数据
仅用于在文本视图中显示联系人姓名contactID.get(position)
正在返回id号,然后将其解析为long。很抱歉,此数据:BitmapFactory.decodeStream(new ByteArrayInputStream(data))
检索到的\u id
不是联系人id
。它是您收件箱中每个mesage的线程id
。正如我向您提出的另一个问题,正确的方法是查找联系人
与地址
匹配。内置收件箱就是这样做的。您确定数据
的内容是以ByteArray格式显示的图像吗?@Graeme数据
仅用于在文本视图中显示联系人姓名contactID.get(position)
正在返回id号,然后将其解析为long。很抱歉,此数据:BitmapFactory.decodeStream(new ByteArrayInputStream(data))
检索到的\u id
不是联系人id
。它是您收件箱中每个mesage的线程id
。正如我向您提出的另一个问题,正确的方法是查找联系人
与地址
匹配。内置收件箱就是这样做的。