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!

4

1 回答 1

0

您应该在读取显示名称的同一查询中读取联系人的 ID。然后您应该阅读ContactsContract.Contacts.Photo以获取读取/显示联系人照片的示例代码。

Android:获取联系方式(ID、姓名、电话、照片)是解决问题的一个很好的例子。


将您的查询修改为(我添加PhoneLookup._ID

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

//并像读取显示名称一样读取id

long id = cs.getLong(cs.getColumnIndex(PhoneLookup._ID));
于 2013-08-28T06:42:45.100 回答