mangstadt/ez-vcard

Image not show on contact

Closed this issue · 4 comments

Hi mangstadt I set photo like this

String imageUrl // image url on google storages
Photo photo = new Photo(imageUrl, ImageType.JPEG);
vcard.addPhoto(photo);

but when I'm import .vcf file to device the image not showing.
How Can I solve it ?

Thank you :)

I think I found it when write file vcard the image url have a space like this

PHOTO;MEDIATYPE=image/jpeg:https://storage.googleapis.com/unicorn-hr/mpy/si
t/employee/03105.jpg

when copy this link and open via browser
https://storage.googleapis.com/unicorn-hr/mpy/si%20t/employee/03105.jpg

link correct
https://storage.googleapis.com/unicorn-hr/mpy/sit/employee/03105.jpg

how I can fix it ?

Thank you :)

The space marks the continuation of the previous line.

Turning off line folding will remove the space.

VCardWriter writer = ...
writer.getVObjectWriter().getFoldedLineWriter().setLineLength(null);
writer.write(vcard);

Thank you. if I would like to set image with base64, I can set like this

String dataBase64Str = Base64.encodeBase64String((byte[]) image);
Photo photo = new Photo(user.get(dataBase64Str, ImageType.JPEG);
vcard.addPhoto(photo);

on vcard version 3

You don't have to base64-encode the image. Just pass a byte array into the Photo constructor.

ez-vcard will perform the base64 encoding when it serializes the vCard.

byte[] imageData = ...
Photo photo = new Photo(imageData, ImageType.JPEG);
vcard.addPhoto(photo);