Large Photo Version from contacts in android

2019-07-24 17:21发布

问题:

I am trying to fetch the larger size picture from my contacts using the following code:

Uri my_contact_Uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.parseLong(contactId));

       InputStream photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), my_contact_Uri);

    if(photo_stream != null) 
    {
        BufferedInputStream buf =new BufferedInputStream(photo_stream);
        Bitmap my_btmp = BitmapFactory.decodeStream(buf);
        profile.setImageBitmap(my_btmp);
    }
    else
    {
        profile.setImageResource(R.drawable.contactpic);
    }

I have an imageview with match_parent (width and height).

All the photos from contacts are blurred. I am sure it is taking the thumbnail picture. How do I get the large picture?

回答1:

You have to use

ContentResolver cr = getContext().getContentResolver();
Uri contactUri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, Long.valueOf(CONTACT_ID));
InputStream photo_stream = ContactsContract.Contacts.openContactPhotoInputStream(cr, contactUri, true);

If you don't enter the boolean parameter, it's false by default, and it will return the thumbnail view.