Skip to content Skip to sidebar Skip to footer

Getting Bitmap From Contacts Fails Even Though Bitmap Uri Is Not Null

I am trying to get the full size Contact image from the Bitmap,I know that this image is not always available...however I found that the uri of the Bitmap was not null but the code

Solution 1:

Solved.Instead of using the AssetFileDescriptor I have instead used the method:

   context.getContentResolver().openInputStream(photoUri);

EDIT: I came back to this problem after some time and I have found that even this does not work.Is there any way to obtain full sized photos from the ContactsProvider API?

Solution 2:

Here is another solution for getting large photos with fallback to contacts thumbnails:

publicstatic Bitmap getContactBigPhoto(Uri contactUri, ContentResolver resolver) {     
        InputStreamphotoInputStream=null;
        try {                       
            photoInputStream = Contacts.openContactPhotoInputStream(resolver, contactUri, true);
            Bitmapphoto= BitmapFactory.decodeStream(photoInputStream);            
            return photo;
        } catch (Exception e) {
            returnnull;
        } finally {
            if(photoInputStream != null) {
                try {
                    photoInputStream.close();
                } catch (IOException e) {

                }               
            }
        }
    }

Solution 3:

// Solved, this code work in my case. with small and large size imagespublic Bitmap getDisplayPhotoBitmap(long contactId) {
            UricontactUri= ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
            InputStreamphotoInputStream=
                    ContactsContract.Contacts.openContactPhotoInputStream(ProspectActivity.this.getContentResolver(), contactUri);
            Bitmapbitmap= BitmapFactory.decodeStream(photoInputStream);
            if (bitmap != null) {
                return bitmap;
            }
            returnnull;
        }

Post a Comment for "Getting Bitmap From Contacts Fails Even Though Bitmap Uri Is Not Null"