Images, Sounds and Keys - george-haddad/cardme GitHub Wiki

The Basics

VCards can hold data such as images, sounds and encryption keys. These pieces of data are converted to BASE64 text encoding and embedded into the VCard. Of course with such large data the text must be folded which is rightly done according to the MIME-DIR specification, this is unless specified other wise using a custom Binary Folding Scheme.

CardMe provides tools in its util package to read a file and return a byte array, encode and decode BASE64 text to bytes and back again, as well as other tools for folding and unfolding. So do not worry about these details as they are all taken care of.

The RFC-2426 standard states that each one of these binary types can be one of the IANA registered media types or a non-standard type. So CardMe provides you with a painful list of IANA registered types for images, sounds and keys. Within them is a special registered type called NON_STANDARD which is used if a non-standard type has been detected and used.

Adding Photo, Logo, Sound and Key

Adding files such as photos, logos or sounds can be done by embedding the file in the VCard or by referencing a URI.

Embedding

PhotoFeature photo = new PhotoType();
photo.setCompression(false);
photo.setEncodingType(EncodingType.BINARY);
photo.setImageMediaType(ImageMediaType.PNG);
byte[] tuxPicture = Util.getFileAsBytes(new File("/home/george/images/smallTux.png"));
photo.setPhoto(tuxPicture);
vcard.addPhoto(photo);

As you may have noticed we set the compression to false. This is the GZIP compression that you can optionally choose to use when embedding a file. By default compression is turned off because of 2 reasons:

  1. Not many app may support or recognize the compression
  2. Compression may make the file larger than it is

Photos, logos and sounds are set by giving it the file in bytes and let CardMe handle the conversion of bytes to and from BASE64.

URI

SoundFeature sound = new SoundType();
sound.setCompression(false);
sound.setEncodingType(EncodingType.BINARY);
sound.setAudioMediaType(AudioMediaType.OGG);
sound.setSoundURI(new File("/home/george/sounds/myVoice.ogg").toURI());
vcard.addSound(sound);

When setting a file as a URI we simply just ignore that there are any bytes. The presence of a URI will be detected over the bytes if its not set.

Keys are added in exactly the same manner:

KeyFeature key = new KeyType();
key.setKeyTextType(KeyTextType.GPG);
key.setEncodingType(EncodingType.BINARY);
byte[] keyBytes = Util.getFileAsBytes(new File("/home/george/mykey.gpg"));
key.setKey(keyBytes);
vcard.addKey(key);

IANA Registered Types

Image Types

  • CGM: image/cgm, .cgm
  • JP2: image/jp2, .jp2
  • JPM: image/jpm, .jpm
  • JPX: image/jpx, .jpf
  • NAPLPS: image/naplps
  • PNG: image/png, .png
  • BTIF: .image/prs.btif, .btif
  • PTI: image/prs.pti, .pti
  • DJVU: image/vnd.djvu, .djvu
  • SVF: image/vnd.svf, .svf
  • WBMP: image/vnd.wap.wbmp, .wbmp
  • PSD: image/vnd.adobe.photoshop, .psd
  • INF2: image/vnd.cns.inf2
  • DWG: image/vnd.dwg, .dwg
  • DXF: image/vnd.dxf, .dxf
  • FBS: image/vnd.fastbidsheet, .fbs
  • FPX: image/vnd.fpx, .fpx
  • FST: image/vnd.fst, .fst
  • MMR: image/vnd.fujixerox.edmics-mmr, .mmr
  • RLC: image/vnd.fujixerox.edmics-rlc, .rlc
  • PGB: image/vnd.globalgraphics.pgb, .pgb
  • ICO: image/vnd.microsoft.icon, .ico
  • MIX: image/vnd.mix
  • MDI: image/vnd.ms-modi, .mdi
  • PIC: image/vnd.radiance, .pic
  • SPNG: image/vnd.sealed.png, .spng
  • SGIF: image/vnd.sealedmedia.softseal.gif, .sgif
  • SJPG: image/vnd.sealedmedia.softseal.jpg, .sjpg
  • XIF: image/vnd.xiff, .xif
  • JPEG: image/jpeg, .jpg

Audio Types

  • GPP3: aduio/3gpp
  • GPP2: aduio/3gpp2
  • AC3: aduio/ac3, .ac3
  • AMR: aduio/amr, .amr
  • AMR_WB: aduio/amr-wb, .amr-wb
  • AMR_WB_PLUS: aduio/amr-wb+, .amr-wb+
  • ASC: aduio/asc
  • ATRAC_ADVANCED_LOSSLESS: aduio/atrac-advanced-lossless
  • ATRAC_X: aduio/atrac-x
  • ATRAC3: aduio/atrac3
  • BASIC: aduio/basic
  • BV16: aduio/bv16
  • BV32: aduio/bv32
  • CLEARMODE: aduio/clearmode
  • CN: aduio/cn
  • DAT12: aduio/dat12
  • DLS: aduio/dls
  • DSR_ES201108: aduio/dsr-es201108
  • DSR_ES202050: aduio/dsr-es202050
  • DSR_ES202211: aduio/dsr-es202211
  • DSR_ES202212: aduio/dsr-es202212
  • EAC3: aduio/eac3, .eac3
  • DVI4: aduio/dvi4
  • EVRC: aduio/evrc
  • EVRC0: aduio/evrc0
  • EVRC1: aduio/evrc1
  • EVRCB: aduio/evrcb
  • EVRCB0: aduio/evrcb0
  • EVRCB1: aduio/evrcb1
  • EVRC_QCP: aduio/evrc-qcp
  • EVRCWB: aduio/evrcwb
  • EVRCWB0: aduio/evrcwb0
  • EVRCWB1: aduio/evrcwb1
  • G719: aduio/g719
  • G722: aduio/g722
  • G7221: aduio/g7221
  • G723: aduio/g723
  • G726_16: aduio/g726-16
  • G726_24: aduio/g726-24
  • G726_32: aduio/g726-32
  • G726_40: aduio/g726-40
  • G728: aduio/g728
  • G729: aduio/g729
  • G7291: aduio/g7291
  • G729D: aduio/g729d
  • G729E: aduio/g729e
  • GSM: aduio/gsm
  • GSM_EFR: aduio/gsm-efr
  • ILBC: aduio/ilbc
  • L8: aduio/l8
  • L16: aduio/l16
  • L20: aduio/l20
  • L24: aduio/l24
  • LPC: aduio/lpc
  • MOBILE_XMF: aduio/mobile-xmf
  • MPA: aduio/mpa, .mpa
  • MP4: aduio/mp4, .mp4
  • MP$_LATM: aduio/mp4-latm
  • MPA_ROBUST: aduio/mpa-robust
  • MPEG: aduio/mpeg, .mpeg
  • MPEG4_GENERIC: aduio/mpeg4-generic, .mpeg
  • OGG: aduio/ogg, .ogg
  • PARITYFEC_1D_INT: audio/1d-interleaved-parityfec
  • PARITYFEC: aduio/parityfec
  • PCMA: aduio/pcma
  • PCMA_WB: aduio/pcma-wb
  • PCMU: aduio/pcmu
  • PCMU_WB: aduio/pcmu-wb
  • PRS_SID: aduio/prs.sid, .sid
  • QCELP: aduio/qcelp
  • RED: aduio/red
  • RTP_MIDI: aduio/rtp-midi
  • RTX: aduio/rtx
  • SMV: aduio/smv
  • SMV0: aduio/smv0
  • SMV_QCP: aduio/smv-qcp
  • SPEEX: aduio/speex
  • T140C: aduio/t140c
  • T38: aduio/t38
  • TELEPHONE_EVENT: aduio/telephone-event
  • TONE: aduio/tone
  • UEMCLIP: aduio/uemclip
  • ULPFEC: aduio/ulpfec
  • VDVI: aduio/vdvi
  • VMR_WB: aduio/vmr-wb
  • VORBIS: aduio/vorbis
  • VORBIS_CONFIG: aduio/vorbis-config
  • RTP_ENC_AESCM128: aduio/rtp-enc-aescm128
  • SP_MIDI: aduio/sp-midi , .mid
  • GPP3_IUFP: aduio/vnd.3gpp.iufp
  • SB4: aduio/vnd.4sb
  • AUDIOKOZ: aduio/vnd.audiokoz, .koz
  • CELP: aduio/vnd.CELP
  • NSE: aduio/vnd.cisco.com
  • CMLES_RADIO_EVENTS: aduio/vnd.cmles.radio-events
  • CNS_ANP1: aduio/vnd.cns.anp1
  • CNS_INF1: aduio/vnd.cns.inf1
  • EOL: aduio/vnd.digital-winds, .eol
  • DLNA_ADTS: aduio/vnd.dlna.adts
  • HEAAC1: aduio/vnd.dolby.heaac.1
  • HEAAC2: aduio/vnd.dolby.heaac.2
  • MPL: aduio/vnd.dolby.mlp, .mpl
  • MPS: aduio/vnd.dolby.mps
  • PL2: aduio/vnd.dolby.pl2
  • PL2X: aduio/vnd.dolby.pl2x
  • PL2Z: aduio/vnd.dolby.pl2z
  • PULSE_1: aduio/vnd.dolby.pulse.1
  • DRA: aduio/vnd.dra
  • DTS: aduio/vnd.dts, .WAV
  • DTSHD: aduio/vnd.dts.hd, .dtshd
  • PLJ: aduio/vnd.everad.plj, .plj
  • AUDIO: aduio/vnd.hns.audio, .rm
  • LVP: aduio/vnd.lucent.voice, .lvp
  • PYA: aduio/vnd.ms-playready.media.pya, .pya
  • MXMF: aduio/vnd.nokia.mobile-xmf, .mxmf
  • VBK: aduio/vnd.nortel.vbk, .vbk
  • ECELP4800: aduio/vnd.nuera.ecelp4800, .ecelp4800
  • ECELP7470: aduio/vnd.nuera.ecelp7470, .ecelp7470
  • ECELP9600: aduio/vnd.nuera.ecelp9600, .ecelp9600
  • SBC: aduio/vnd.octel.sbc
  • KADPCM32: aduio/vnd.rhetorex.32kadpcm
  • SMP3: aduio/vnd.sealedmedia.softseal.mpeg, .smp3
  • CVSD: aduio/vnd.vmx.cvsd

Key Types

  • PGP: PGP, .pgp
  • GPG: GPG, .gpg
  • X509: X509
  • B: B
⚠️ **GitHub.com Fallback** ⚠️