0

I am able to retrieve SMS conversation from the query properly and it is working. Now I would like to add photo of particular contact? I was able to get the contact's display name by putting the following:

 Cursor cs= getContentResolver().query(Nameuri, new String[]{PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);

            if(cs.getCount()>0)
            {
                cs.moveToFirst();
                contactName = cs.getString(cs.getColumnIndex(PhoneLookup.DISPLAY_NAME));
            } 

I am not able to find PhoneLookup._ID? Is there any easy way retrieve photo similar to Display_name?

Let me know!

Thanks!

TheDevMan
  • 5,914
  • 12
  • 74
  • 144

1 Answers1

0

You should read id of the contact in same query in which you are reading display name. And then you should read ContactsContract.Contacts.Photo for an example code to read/ display Contact photo.

Android: Get Contact Details (ID, Name, Phone, Photo) can be a very good example to solve your problem.


Modify your query as (I added PhoneLookup._ID)

Cursor cs= getContentResolver().query(Nameuri, new String[]{PhoneLookup._ID, PhoneLookup.DISPLAY_NAME},PhoneLookup.NUMBER+"='"+address+"'",null,null);

//And read the id as same as you read display name

long id = cs.getLong(cs.getColumnIndex(PhoneLookup._ID));
Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186