Android - Retrieve Contact Photo and Display

前端 未结 1 960
暗喜
暗喜 2021-01-13 10:45

I am creating a simple application that retrieves the name and phone number of each individual contact and display in a list view along with the contact\'s photo in a thumbn

相关标签:
1条回答
  • 2021-01-13 11:07

    You try to get the contact id of the contact(phonenumber) and use Bitmapfactory to decode the image as shown in below working code.

    InputStream inputStream=null;
    String[] projection = new String[]{Contacts._ID};
    Uri contactUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI,Uri.encode(phnumber));
    Cursor c = getContentResolver().query(contactUri, projection,
        null, null, null);
    if (c.moveToFirst()) {
        long contactId=c.getColumnIndex(Contacts._ID);
    
        inputStream = Contacts.openContactPhotoInputStream(activity.getContentResolver(),
                                ContentUris.withAppendedId(Contacts.CONTENT_URI, cntID));
        c.close();
    
    }
    

    use the inputstream to get bitmap

    Bitmap bitmap= BitmapFactory.decodeStream(inputStream);
     holder.ivPic.setImageBitmap(bitmap);
    
    0 讨论(0)
提交回复
热议问题