Blaze Tama
Blaze Tama

Reputation: 10948

Adding the user's contact's photo from phone to ListView? :D

I have created a list of contact's in user phone, now i want to add the user's photo (not from fb) how to create that? :D This is a piece of my code :

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ContentResolver cr = getContentResolver();
    Cursor cursor = cr.query(Uri.parse("content://sms/inbox"), null, null,
            null, null);

    int indexBody = cursor.getColumnIndex("body");
    int indexAddr = cursor.getColumnIndex("address");

    if (indexBody < 0 || !cursor.moveToFirst())
        return;

    smsList.clear();

    do {
        String str = "Sender : " + cursor.getString(indexAddr) + "\n"
                + cursor.getString(indexBody);
        smsList.add(str);
        // ADDRESS[total] = cursor.getString(indexAddr);
        // total++;
    } while (cursor.moveToNext());

    ListView lvSms = (ListView) findViewById(R.id.SMSList);
    lvSms.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, smsList));

    // cursor.requery();
    lvSms.setOnItemClickListener(this);
}

I create the list in this code :

do {
        String str = "Sender : " + cursor.getString(indexAddr) + "\n"
                + cursor.getString(indexBody);
        smsList.add(str);
        // ADDRESS[total] = cursor.getString(indexAddr);
        // total++;
    } while (cursor.moveToNext());

    ListView lvSms = (ListView) findViewById(R.id.SMSList);
    lvSms.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, smsList));

    // cursor.requery();
    lvSms.setOnItemClickListener(this);

Thats all, i found that i must use Bitmap, is it true? Thanks all :D

PS : English is not my native languange, so sorry if i made some mistake's :D

Upvotes: 1

Views: 684

Answers (1)

Karthi
Karthi

Reputation: 13752

Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI,
                contactId);
        Uri photoUri = Uri.withAppendedPath(contactUri,
                Contacts.Photo.CONTENT_DIRECTORY);
        Cursor cursor = getContentResolver().query(photoUri, null, null, null,
                null);

using this query you can fetch the image url for your user photos in your contact list, in order to display along with name and number in list , you have to Base or any other custom adapter.

Upvotes: 2

Related Questions