diff --git a/source/org/jivesoftware/smackx/packet/VCard.java b/source/org/jivesoftware/smackx/packet/VCard.java index a05842406..7c4234a61 100644 --- a/source/org/jivesoftware/smackx/packet/VCard.java +++ b/source/org/jivesoftware/smackx/packet/VCard.java @@ -355,6 +355,26 @@ public class VCard extends IQ { setField("PHOTO", "image/jpeg" + encodedImage + "", true); } + /** + * Specify the bytes for the avatar to use as well as the mime type. + * + * @param bytes the bytes of the avatar. + * @param mimeType the mime type of the avatar. + */ + public void setAvatar(byte[] bytes, String mimeType) { + if (bytes == null) { + // Remove avatar (if any) from mappings + otherUnescapableFields.remove("PHOTO"); + return; + } + + // Otherwise, add to mappings. + String encodedImage = StringUtils.encodeBase64(bytes); + avatar = encodedImage; + + setField("PHOTO", "" + mimeType + "" + encodedImage + "", true); + } + /** * Set the encoded avatar string. This is used by the provider. *