2

重要的是要注意,我使用的 API 是 2.3

我有一个列表视图,当前由在我的设备收件箱中向我发送短信的联系人(目前为 6 个)填充。在收集所有联系人并将其传递到ArrayList<String>中之后,ArrayList 将传递到我的CustomAdapter类的构造函数中。从那里,这是用我的方法中的收件箱中的联系人填充我的列表视图的代码getView()

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));
}

从上面的代码中,holder.contact显示 6 个联系人没有问题。但问题是holder.photowhich 什么都没有显示。这是假设获取照片的方法:

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;
    }

但在 LogCat 中,这是唯一显示参考照片的内容:

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}

有关解决此问题以显示联系人照片的任何想法?

4

0 回答 0