2

IMPORTANT TO NOTE THAT THE API IM WORKING WITH IS 2.3

I have a listview that is currently populated by the contacts (currently 6) who have sent me text messages in my device's inbox. After all contacts are collected and passed into an ArrayList<String>, the ArrayList is then passed into a constructor for my CustomAdapter class. From there, this is the code that populates my listview with the contacts from my inbox from within my getView() method:

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

From the above code, holder.contact displays 6 contacts with no problem. But the problem is with holder.photo which displays nothing at all. Here is the method that is suppose to get the photos:

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

But in LogCat, this is the only thing displaying in reference to the photos:

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}

Any ideas as to fix this so that the contact photos are displayed?

Ankur
  • 5,086
  • 19
  • 37
  • 62
  • Are you sure the contents of `data` is an image as a ByteArray? – Graeme Jun 14 '12 at 08:43
  • @Graeme `data` is only being used to display the contact name in a TextView. `contactID.get(position)` is returning the id number, then parsed into a long. –  Jun 14 '12 at 08:48
  • Sorry, this `data`: `BitmapFactory.decodeStream( new ByteArrayInputStream(data))` – Graeme Jun 14 '12 at 08:51
  • The `_id` you retrieved is not `Contact_id`. It's `thread_id` of each mesage you had in inbox. As i suggested you another question, the right way is find `Contact` matched with `address`. That is how built-in Inbox did. – Trung Nguyen Sep 01 '12 at 11:20

0 Answers0