Large Photo Version from contacts in android

我与影子孤独终老i 提交于 2019-12-11 01:28:23

问题


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.



来源:https://stackoverflow.com/questions/22368289/large-photo-version-from-contacts-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!