mangstadt / ez-vcard

A vCard parser library for Java
Other
401 stars 92 forks source link

Image not show on contact #94

Closed bosemian closed 5 years ago

bosemian commented 5 years ago

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 :)

bosemian commented 5 years ago

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 :)

mangstadt commented 5 years ago

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);
bosemian commented 5 years ago

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

mangstadt commented 5 years ago

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);